Skip to content
Flecs v4.1
script.h File Reference

Flecs script module. More...

Go to the source code of this file.

Classes

struct  ecs_script_var_t
 Script variable. More...
struct  ecs_script_vars_t
 Script variable scope. More...
struct  ecs_script_t
 Script object. More...
struct  EcsScript
 Script component. More...
struct  ecs_function_ctx_t
 Script function context. More...
struct  ecs_script_parameter_t
 Function argument type. More...
struct  ecs_script_eval_desc_t
 Used with ecs_script_parse() and ecs_script_eval(). More...
struct  ecs_script_eval_result_t
 Used to capture error output from script evaluation. More...
struct  EcsScriptConstVar
 Const component. More...
struct  EcsScriptMutVar
 Mut component. More...
struct  ecs_script_function_t
struct  ecs_script_source_t
 Source location of a script statement. More...
struct  ecs_script_desc_t
 Used with ecs_script_init(). More...
struct  ecs_expr_eval_desc_t
 Used with ecs_expr_run(). More...
struct  ecs_const_var_desc_t
 Used with ecs_const_var_init(). More...
struct  ecs_mut_var_desc_t
 Used with ecs_mut_var_init(). More...
struct  ecs_vector_fn_callbacks_t
 Vector function callbacks for different element types. More...
struct  ecs_function_desc_t
 Used with ecs_function_init() and ecs_method_init(). More...

Macros

#define FLECS_SCRIPT_H
#define FLECS_SCRIPT_FUNCTION_ARGS_MAX   (16)
#define FLECS_SCRIPT_VECTOR_FUNCTION_COUNT   (18)
#define ecs_script(world, ...)
#define ecs_script_vars_define(vars, name, type)
#define ecs_const_var(world, ...)
#define ecs_const_var_get_t(world, name, T)
 Return pointer to the value of a const variable.
#define ecs_mut_var(world, ...)
#define ecs_mut_var_get_t(world, name, T)
 Return pointer to the value of a mut variable.
#define ecs_mut_var_set_t(world, name, T, ...)
 Set the value of a mut variable.
#define ecs_function(world, ...)
#define ecs_method(world, ...)

Typedefs

typedef struct ecs_script_template_t ecs_script_template_t
typedef struct ecs_script_var_t ecs_script_var_t
 Script variable.
typedef struct ecs_script_vars_t ecs_script_vars_t
 Script variable scope.
typedef struct ecs_script_t ecs_script_t
 Script object.
typedef struct ecs_script_runtime_t ecs_script_runtime_t
 Runtime for executing scripts.
typedef struct EcsScript EcsScript
 Script component.
typedef struct ecs_function_ctx_t ecs_function_ctx_t
 Script function context.
typedef void(*) ecs_function_callback_t(const ecs_function_ctx_t *ctx, int32_t argc, const ecs_value_t *argv, ecs_value_t *result)
 Script function callback.
typedef void(*) ecs_vector_function_callback_t(const ecs_function_ctx_t *ctx, int32_t argc, const ecs_value_t *argv, ecs_value_t *result, int32_t elem_count)
 Script vector function callback.
typedef struct ecs_script_parameter_t ecs_script_parameter_t
 Function argument type.
typedef struct ecs_script_eval_desc_t ecs_script_eval_desc_t
 Used with ecs_script_parse() and ecs_script_eval().
typedef struct ecs_script_eval_result_t ecs_script_eval_result_t
 Used to capture error output from script evaluation.
typedef struct EcsScriptConstVar EcsScriptConstVar
 Const component.
typedef struct EcsScriptMutVar EcsScriptMutVar
 Mut component.
typedef struct ecs_script_function_t EcsScriptFunction
 Function component.
typedef struct ecs_script_function_t EcsScriptMethod
 Method component.
typedef struct ecs_script_source_t ecs_script_source_t
 Source location of a script statement.
typedef struct ecs_script_edits_t ecs_script_edits_t
 Set of pending edits for a script.
typedef struct ecs_script_desc_t ecs_script_desc_t
 Used with ecs_script_init().
typedef struct ecs_expr_eval_desc_t ecs_expr_eval_desc_t
 Used with ecs_expr_run().
typedef struct ecs_const_var_desc_t ecs_const_var_desc_t
 Used with ecs_const_var_init().
typedef struct ecs_mut_var_desc_t ecs_mut_var_desc_t
 Used with ecs_mut_var_init().
typedef struct ecs_vector_fn_callbacks_t ecs_vector_fn_callbacks_t
 Vector function callbacks for different element types.
typedef struct ecs_function_desc_t ecs_function_desc_t
 Used with ecs_function_init() and ecs_method_init().
typedef struct ecs_expr_node_t ecs_expr_node_t

Functions

FLECS_API ECS_COMPONENT_DECLARE (EcsScript)
FLECS_API ECS_DECLARE (EcsScriptTemplate)
FLECS_API ECS_DECLARE (EcsScriptTemplateManual)
FLECS_API ECS_DECLARE (EcsScriptTemplatePending)
FLECS_API int ecs_script_template_update (ecs_world_t *world, ecs_entity_t instance, ecs_entity_t template_entity)
FLECS_API ECS_COMPONENT_DECLARE (EcsScriptConstVar)
FLECS_API ECS_COMPONENT_DECLARE (EcsScriptMutVar)
FLECS_API ECS_COMPONENT_DECLARE (EcsScriptFunction)
FLECS_API ECS_DECLARE (EcsScriptVectorType)
FLECS_API ecs_script_t * ecs_script_parse (ecs_world_t *world, const char *name, const char *code, const ecs_script_eval_desc_t *desc, ecs_script_eval_result_t *result)
 Parse script.
FLECS_API int ecs_script_eval (const ecs_script_t *script, const ecs_script_eval_desc_t *desc, ecs_script_eval_result_t *result)
 Evaluate script.
FLECS_API void ecs_script_free (ecs_script_t *script)
 Free script.
FLECS_API int ecs_script_run (ecs_world_t *world, const char *name, const char *code, ecs_script_eval_result_t *result)
 Parse script.
FLECS_API int ecs_script_run_w_desc (ecs_world_t *world, const char *name, const char *code, const ecs_script_eval_desc_t *desc, ecs_script_eval_result_t *result)
 Parse script and evaluate with options.
FLECS_API int ecs_script_run_file (ecs_world_t *world, const char *filename)
 Parse script file.
FLECS_API int ecs_script_run_file_w_desc (ecs_world_t *world, const char *filename, const ecs_script_eval_desc_t *desc)
 Parse script file and evaluate with options.
FLECS_API char * ecs_script_ir_to_str (const ecs_script_t *script)
 Convert script IR to string.
FLECS_API ecs_script_runtime_t * ecs_script_runtime_new (void)
 Create runtime for script.
FLECS_API void ecs_script_runtime_free (ecs_script_runtime_t *runtime)
 Free script runtime.
FLECS_API int ecs_script_ast_to_buf (ecs_script_t *script, ecs_strbuf_t *buf, bool colors)
 Convert script AST to string.
FLECS_API char * ecs_script_ast_to_str (ecs_script_t *script, bool colors)
 Convert script AST to string.
FLECS_API bool ecs_script_entity_source (const ecs_script_t *script, ecs_entity_t entity, ecs_script_source_t *source)
 Find the statement that declares an entity.
FLECS_API ecs_entity_t ecs_script_entity_owner (const ecs_world_t *world, ecs_entity_t entity)
 Find the managed script that declares an entity.
FLECS_API ecs_script_edits_t * ecs_script_edits_new (ecs_script_t *script)
 Create an edit set for a script.
FLECS_API void ecs_script_edits_free (ecs_script_edits_t *edits)
 Free an edit set.
FLECS_API int ecs_script_edits_set (ecs_script_edits_t *edits, ecs_entity_t entity, ecs_id_t component, const void *value)
 Set a component value on an entity.
FLECS_API int ecs_script_edits_set_expr (ecs_script_edits_t *edits, ecs_entity_t entity, ecs_id_t component, const char *expr)
 Set a component value on an entity from an expression string.
FLECS_API int ecs_script_edits_remove (ecs_script_edits_t *edits, ecs_entity_t entity, ecs_id_t component)
 Remove a component from an entity.
FLECS_API int ecs_script_edits_delete (ecs_script_edits_t *edits, ecs_entity_t entity)
 Delete an entity.
FLECS_API int ecs_script_edits_clear (ecs_script_edits_t *edits, ecs_entity_t entity, ecs_id_t component)
 Remove a recorded edit from an edit set.
FLECS_API int32_t ecs_script_edits_count (const ecs_script_edits_t *edits)
 Return the number of recorded edits in an edit set.
FLECS_API char * ecs_script_edits_apply (const ecs_script_edits_t *edits)
 Apply an edit set.
FLECS_API ecs_entity_t ecs_script_init (ecs_world_t *world, const ecs_script_desc_t *desc)
 Load managed script.
FLECS_API int ecs_script_update (ecs_world_t *world, ecs_entity_t script, ecs_entity_t instance, const char *code)
 Update script with new code.
FLECS_API void ecs_script_clear (ecs_world_t *world, ecs_entity_t script, ecs_entity_t instance)
 Clear all entities associated with script.
FLECS_API ecs_script_vars_t * ecs_script_vars_init (ecs_world_t *world)
 Create new variable scope.
FLECS_API void ecs_script_vars_fini (ecs_script_vars_t *vars)
 Free variable scope.
FLECS_API ecs_script_vars_t * ecs_script_vars_push (ecs_script_vars_t *parent)
 Push new variable scope.
FLECS_API ecs_script_vars_t * ecs_script_vars_pop (ecs_script_vars_t *vars)
 Pop variable scope.
FLECS_API ecs_script_var_t * ecs_script_vars_declare (ecs_script_vars_t *vars, const char *name)
 Declare a variable.
FLECS_API ecs_script_var_t * ecs_script_vars_define_id (ecs_script_vars_t *vars, const char *name, ecs_entity_t type)
 Define a variable.
FLECS_API ecs_script_var_t * ecs_script_vars_lookup (const ecs_script_vars_t *vars, const char *name)
 Lookup a variable.
FLECS_API ecs_script_var_t * ecs_script_vars_from_sp (const ecs_script_vars_t *vars, int32_t sp)
 Lookup a variable by stack pointer.
FLECS_API void ecs_script_vars_print (const ecs_script_vars_t *vars)
 Print variables.
FLECS_API void ecs_script_vars_set_size (ecs_script_vars_t *vars, int32_t count)
 Preallocate space for variables.
FLECS_API void ecs_script_vars_from_iter (const ecs_iter_t *it, ecs_script_vars_t *vars, int offset)
 Convert iterator to vars.
FLECS_API const char * ecs_expr_run (ecs_world_t *world, const char *ptr, ecs_value_t *value, const ecs_expr_eval_desc_t *desc)
 Run expression.
FLECS_API ecs_script_t * ecs_expr_parse (ecs_world_t *world, const char *expr, const ecs_expr_eval_desc_t *desc)
 Parse expression.
FLECS_API int ecs_expr_eval (const ecs_script_t *script, ecs_value_t *value, const ecs_expr_eval_desc_t *desc)
 Evaluate expression.
FLECS_API char * ecs_script_string_interpolate (ecs_world_t *world, const char *str, const ecs_script_vars_t *vars)
 Evaluate interpolated expressions in string.
FLECS_API ecs_entity_t ecs_const_var_init (ecs_world_t *world, ecs_const_var_desc_t *desc)
 Create a const variable that can be accessed by scripts.
FLECS_API ecs_value_t ecs_const_var_get (const ecs_world_t *world, ecs_entity_t var)
 Return the value for a const variable.
FLECS_API void * ecs_const_var_get_w_type (const ecs_world_t *world, const char *name, ecs_entity_t type, ecs_size_t size, void *out)
 Return pointer to the value of a const variable.
FLECS_API ecs_entity_t ecs_mut_var_init (ecs_world_t *world, ecs_mut_var_desc_t *desc)
 Create a mut variable that can be accessed by scripts.
FLECS_API ecs_value_t ecs_mut_var_get (const ecs_world_t *world, ecs_entity_t var)
 Return the value for a mut variable.
FLECS_API void * ecs_mut_var_get_w_type (const ecs_world_t *world, const char *name, ecs_entity_t type, ecs_size_t size, void *out)
 Return pointer to the value of a mut variable.
FLECS_API int ecs_mut_var_set_w_type (ecs_world_t *world, const char *name, ecs_entity_t type, ecs_size_t size, const void *value)
 Set the value of a mut variable.
FLECS_API void ecs_mut_var_modified (ecs_world_t *world, ecs_entity_t var)
 Mark mut var as modified.
FLECS_API ecs_entity_t ecs_function_init (ecs_world_t *world, const ecs_function_desc_t *desc)
 Create new function.
FLECS_API int ecs_function_call (ecs_world_t *world, ecs_entity_t function, int32_t argc, const ecs_value_t *argv, ecs_value_t *result)
FLECS_API ecs_entity_t ecs_method_init (ecs_world_t *world, const ecs_function_desc_t *desc)
 Create new method.
FLECS_API int ecs_method_call (ecs_world_t *world, ecs_entity_t method, const ecs_value_t *instance, int32_t argc, const ecs_value_t *argv, ecs_value_t *result)
FLECS_API char * ecs_ptr_to_expr (const ecs_world_t *world, ecs_entity_t type, const void *data)
 Serialize value into expression string.
FLECS_API int ecs_ptr_to_expr_buf (const ecs_world_t *world, ecs_entity_t type, const void *data, ecs_strbuf_t *buf)
 Serialize value into expression buffer.
FLECS_API char * ecs_ptr_to_str (const ecs_world_t *world, ecs_entity_t type, const void *data)
 Similar to ecs_ptr_to_expr(), but serializes values to string.
FLECS_API int ecs_ptr_to_str_buf (const ecs_world_t *world, ecs_entity_t type, const void *data, ecs_strbuf_t *buf)
 Serialize value into string buffer.
FLECS_API void FlecsScriptImport (ecs_world_t *world)
 Script module import function.

Detailed Description

Flecs script module.

For script examples, see examples/script.

Definition in file script.h.