37#define FLECS_SCRIPT_FUNCTION_ARGS_MAX (16)
40#define FLECS_SCRIPT_VECTOR_FUNCTION_COUNT (18)
62int ecs_script_template_update(
83typedef struct ecs_script_template_t ecs_script_template_t;
203#ifdef FLECS_SCRIPT_ASYNC
230#ifdef FLECS_SCRIPT_ASYNC
231 ecs_async_function_callback_t async_callback;
232 ecs_async_function_cancel_t async_cancel;
362 const char *filename);
376 const char *filename,
390#ifdef FLECS_SCRIPT_IR_PROFILE
394void ecs_script_ir_profile_reset(
void);
399char* ecs_script_ir_profile_str(
void);
807#define ecs_script(world, ...)\
808 ecs_script_init(world, &(ecs_script_desc_t) __VA_ARGS__)
936#define ecs_script_vars_define(vars, name, type)\
937 ecs_script_vars_define_id(vars, name, ecs_id(type))
1167#define ecs_const_var(world, ...)\
1168 ecs_const_var_init(world, &(ecs_const_var_desc_t)__VA_ARGS__)
1226#define ecs_const_var_get_t(world, name, T)\
1227 (*ECS_CAST(T*, ecs_const_var_get_w_type(\
1228 world, name, ecs_id(T), ECS_SIZEOF(T), &(T){0})))
1263#define ecs_mut_var(world, ...)\
1264 ecs_mut_var_init(world, &(ecs_mut_var_desc_t)__VA_ARGS__)
1322#define ecs_mut_var_get_t(world, name, T)\
1323 (*ECS_CAST(T*, ecs_mut_var_get_w_type(\
1324 world, name, ecs_id(T), ECS_SIZEOF(T), &(T){0})))
1372#define ecs_mut_var_set_t(world, name, T, ...)\
1373 ecs_mut_var_set_w_type(\
1374 world, name, ecs_id(T), ECS_SIZEOF(T), &(T)__VA_ARGS__)
1478#define ecs_function(world, ...)\
1479 ecs_function_init(world, &(ecs_function_desc_t)__VA_ARGS__)
1482int ecs_function_call(
1506#define ecs_method(world, ...)\
1507 ecs_method_init(world, &(ecs_function_desc_t)__VA_ARGS__)
1585typedef struct ecs_expr_node_t ecs_expr_node_t;
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_script_runtime_free(ecs_script_runtime_t *runtime)
Free script runtime.
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_vars_print(const ecs_script_vars_t *vars)
Print variables.
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 void ecs_script_vars_set_size(ecs_script_vars_t *vars, int32_t count)
Preallocate space for variables.
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 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_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.
struct ecs_script_edits_t ecs_script_edits_t
Set of pending edits for a script.
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.
FLECS_API ecs_script_runtime_t * ecs_script_runtime_new(void)
Create runtime for script.
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_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 ecs_entity_t ecs_function_init(ecs_world_t *world, const ecs_function_desc_t *desc)
Create new function.
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.
struct ecs_script_function_t EcsScriptMethod
Method component.
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 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 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.
FLECS_API ecs_entity_t ecs_script_init(ecs_world_t *world, const ecs_script_desc_t *desc)
Load managed script.
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_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_value_t ecs_const_var_get(const ecs_world_t *world, ecs_entity_t var)
Return the value for a const 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.
struct ecs_script_function_t EcsScriptFunction
Function component.
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 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 ecs_script_edits_t * ecs_script_edits_new(ecs_script_t *script)
Create an edit set for a script.
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 void ecs_script_vars_from_iter(const ecs_iter_t *it, ecs_script_vars_t *vars, int offset)
Convert iterator to vars.
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 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.
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 char * ecs_script_edits_apply(const ecs_script_edits_t *edits)
Apply an edit set.
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_edits_remove(ecs_script_edits_t *edits, ecs_entity_t entity, ecs_id_t component)
Remove a component from an entity.
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.
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_edits_delete(ecs_script_edits_t *edits, ecs_entity_t entity)
Delete an entity.
FLECS_API char * ecs_script_ir_to_str(const ecs_script_t *script)
Convert script IR to string.
FLECS_API ecs_script_vars_t * ecs_script_vars_push(ecs_script_vars_t *parent)
Push new variable scope.
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.
struct ecs_script_runtime_t ecs_script_runtime_t
Runtime for executing scripts.
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.
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.
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.
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.
FLECS_API void ecs_script_edits_free(ecs_script_edits_t *edits)
Free an edit set.
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_script_entity_owner(const ecs_world_t *world, ecs_entity_t entity)
Find the managed script that declares an entity.
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.
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
script_builder script(const char *name=nullptr) const
Build a script.
#define ECS_DECLARE(id)
Forward declare an entity, tag, prefab, or any other entity identifier.
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
void(*) ecs_ctx_free_t(void *ctx)
Function to clean up context data.
Async/await support for Flecs script.
ecs_vec_t observers
Observers for referenced components.
ecs_vec_t dyn_observers
Observers for refs resolved at runtime.
ecs_script_template_t * template_
Only set for template scripts.
char * error
Set if script evaluation had errors.
char * code
Script source code.
bool ir
Evaluate script with IR runtime.
ecs_script_t * script
Parsed script object.
char * filename
Script filename.
bool skip_unknown
Skip unknown components when loading.
Used with ecs_const_var_init().
ecs_entity_t parent
Variable parent (namespace).
const char * name
Variable name.
ecs_entity_t type
Variable type.
void * value
Pointer to value of variable.
Used with ecs_expr_run().
bool disable_folding
Disable constant folding (slower evaluation, faster parsing).
void * script_visitor
For internal usage.
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.
ecs_entity_t function
The function entity.
ecs_world_t * world
The world.
ecs_entity_t entity
"this" entity (for methods and async functions).
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_vector_function_callback_t vector_callbacks[(18)]
Vector function implementations.
ecs_entity_t parent
Parent of function.
Used with ecs_mut_var_init().
void * value
Pointer to value of variable.
ecs_entity_t type
Variable type.
const char * name
Variable name.
ecs_entity_t parent
Variable parent (namespace).
Used with ecs_script_init().
const char * code
Set to parse script from string.
ecs_entity_t entity
Set to customize entity handle associated with script.
bool skip_unknown
Skip unknown identifiers (see ecs_script_eval_desc_t::skip_unknown).
bool ir
Evaluate script with IR runtime.
const char * filename
Set to load script from file.
Used with ecs_script_parse() and ecs_script_eval().
bool ir
Evaluate script with the IR runtime instead of the AST interpreter.
ecs_script_runtime_t * runtime
Reusable runtime (optional).
bool skip_unknown
Skip unknown identifiers.
Used to capture error output from script evaluation.
char * error
Error message, or NULL if no error.
int32_t line
Line number (1-based) of first error, or 0 if not available.
int32_t column
Column number (1-based) of first error, or 0 if not available.
const char * name
Parameter name.
ecs_entity_t type
Parameter type.
Source location of a script statement.
int32_t line
Line of the first character (1 based).
int32_t offset
Offset of the first character of the statement.
bool has_scope
Whether the statement is followed by a { } scope.
ecs_entity_t template_
Set when the statement is inside the body of a template statement.
int32_t length
Number of bytes occupied by the statement.
int32_t column
Column of the first character (1 based).
const char * code
Script source code.
const char * name
Script name.
ecs_world_t * world
The world.
bool is_const
Whether the variable is constant.
ecs_value_t value
Variable value.
bool owned
Whether the scope owns the value storage.
const char * name
Variable name.
const ecs_type_info_t * type_info
Type information.
int32_t sp
Stack pointer for this scope.
ecs_allocator_t * allocator
General purpose allocator.
struct ecs_script_vars_t * parent
Parent variable scope.
struct ecs_stack_t * stack
Stack allocator for variable storage.
ecs_stack_cursor_t * cursor
Cursor into the stack allocator.
ecs_hashmap_t var_index
Index for variable name lookups.
const ecs_world_t * world
The world.
ecs_vec_t vars
Vector of variables in this scope.
Type that contains component information (passed to ctors/dtors/...).
Vector function callbacks for different element types.
ecs_vector_function_callback_t i8
Callback for i8 element type.
ecs_vector_function_callback_t i32
Callback for i32 element type.