34#define FLECS_SCRIPT_FUNCTION_ARGS_MAX (16)
40extern ECS_DECLARE(EcsScriptTemplate);
52typedef struct ecs_script_template_t ecs_script_template_t;
68 ecs_hashmap_t var_index;
72 struct ecs_stack_t *stack;
73 ecs_stack_cursor_t *cursor;
74 ecs_allocator_t *allocator;
85typedef struct ecs_script_runtime_t ecs_script_runtime_t;
92 ecs_script_template_t *template_;
236 const char *filename);
261 ecs_script_runtime_t *runtime);
295 const char *filename;
314#define ecs_script(world, ...)\
315 ecs_script_init(world, &(ecs_script_desc_t) __VA_ARGS__)
441#define ecs_script_vars_define(vars, name, type)\
442 ecs_script_vars_define_id(vars, name, ecs_id(type))
669#define ecs_const_var(world, ...)\
670 ecs_const_var_init(world, &(ecs_const_var_desc_t)__VA_ARGS__)
708#define ecs_function(world, ...)\
709 ecs_function_init(world, &(ecs_function_desc_t)__VA_ARGS__)
728#define ecs_method(world, ...)\
729 ecs_method_init(world, &(ecs_function_desc_t)__VA_ARGS__)
798typedef struct ecs_expr_node_t ecs_expr_node_t;
FLECS_API void ecs_script_runtime_free(ecs_script_runtime_t *runtime)
Free script runtime.
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 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 ecs_script_t * ecs_expr_parse(ecs_world_t *world, const char *expr, const ecs_expr_eval_desc_t *desc)
Parse expression.
FLECS_API void ecs_script_vars_fini(ecs_script_vars_t *vars)
Free variable scope.
struct ecs_expr_eval_desc_t ecs_expr_eval_desc_t
Used with ecs_expr_run().
FLECS_API ecs_script_runtime_t * ecs_script_runtime_new(void)
Create runtime for script.
struct EcsScript EcsScript
Script component.
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 ecs_entity_t ecs_function_init(ecs_world_t *world, const ecs_function_desc_t *desc)
Create new function.
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)
Parse script.
struct EcsScriptConstVar EcsScriptConstVar
Const component.
FLECS_API char * ecs_ptr_to_str(const ecs_world_t *world, ecs_entity_t type, const void *data)
Similar as ecs_ptr_to_expr(), but serializes values to string.
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 char * ecs_script_ast_to_str(ecs_script_t *script, bool colors)
Convert script AST to string.
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.
FLECS_API ecs_entity_t ecs_script_init(ecs_world_t *world, const ecs_script_desc_t *desc)
Load managed script.
struct ecs_const_var_desc_t ecs_const_var_desc_t
Used with ecs_const_var_init.
FLECS_API ecs_script_vars_t * ecs_script_vars_pop(ecs_script_vars_t *vars)
Pop variable scope.
FLECS_API int ecs_script_run(ecs_world_t *world, const char *name, const char *code)
Parse script.
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_clear(ecs_world_t *world, ecs_entity_t script, ecs_entity_t instance)
Clear all entities associated with script.
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 void ecs_script_vars_from_iter(const ecs_iter_t *it, ecs_script_vars_t *vars, int offset)
Convert iterator to vars This operation converts an iterator to a variable array.
FLECS_API void ecs_script_free(ecs_script_t *script)
Free script.
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 ecs_entity_t ecs_method_init(ecs_world_t *world, const ecs_function_desc_t *desc)
Create new method.
struct ecs_script_t ecs_script_t
Script object.
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 int ecs_script_eval(const ecs_script_t *script, const ecs_script_eval_desc_t *desc)
Evaluate script.
struct ecs_script_desc_t ecs_script_desc_t
Used with ecs_script_init()
FLECS_API ecs_script_vars_t * ecs_script_vars_init(ecs_world_t *world)
Create new variable scope.
FLECS_API int ecs_expr_eval(const ecs_script_t *script, ecs_value_t *value, const ecs_expr_eval_desc_t *desc)
Evaluate expression.
struct ecs_function_desc_t ecs_function_desc_t
Used with ecs_function_init and ecs_method_init.
FLECS_API ecs_script_vars_t * ecs_script_vars_push(ecs_script_vars_t *parent)
Push new variable scope.
struct ecs_script_eval_desc_t ecs_script_eval_desc_t
Used with ecs_script_parse() and ecs_script_eval()
struct ecs_script_vars_t ecs_script_vars_t
Script variable scope.
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 void FlecsScriptImport(ecs_world_t *world)
Script module import function.
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.
struct EcsScriptFunction EcsScriptFunction
Function component.
struct ecs_function_ctx_t ecs_function_ctx_t
Script function context.
struct ecs_script_parameter_t ecs_script_parameter_t
Function argument type.
struct ecs_script_var_t ecs_script_var_t
Script variable.
FLECS_API int ecs_script_run_file(ecs_world_t *world, const char *filename)
Parse script file.
FLECS_API ecs_script_var_t * ecs_script_vars_lookup(const ecs_script_vars_t *vars, const char *name)
Lookup a variable.
struct EcsScriptMethod EcsScriptMethod
Method component.
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.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
script_builder script(const char *name=nullptr) const
Build script.
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
Used with ecs_const_var_init.
Used with ecs_expr_run().
bool disable_folding
Disable constant folding (slower evaluation, faster parsing)
ecs_entity_t type
Type of parsed value (optional)
const ecs_script_vars_t * vars
Variables accessible in expression.
ecs_script_runtime_t * runtime
Reusable runtime (optional)
bool allow_unresolved_identifiers
Allow for unresolved identifiers when parsing.
const char * name
Script name.
const char * expr
Full expression string.
bool disable_dynamic_variable_binding
This option instructs the expression runtime to lookup variables by stack pointer instead of by name,...
void * lookup_ctx
Context passed to lookup function.
Used with ecs_function_init and ecs_method_init.
ecs_entity_t return_type
Function return type.
const char * name
Function name.
ecs_script_parameter_t params[(16)]
Function parameters.
void * ctx
Context passed to function implementation.
ecs_function_callback_t callback
Function implementation.
ecs_entity_t parent
Parent of function.
Used with ecs_script_init()
Used with ecs_script_parse() and ecs_script_eval()
ecs_script_runtime_t * runtime
Reusable runtime (optional)
ecs_script_vars_t * vars
Variables used by script.
Type that contains component information (passed to ctors/dtors/...)
Utility to hold a value of a dynamic type.