Skip to content
Flecs v4.1
script.h
Go to the documentation of this file.
1/**
2 * @file addons/script.h
3 * @brief Flecs script module.
4 *
5 * For script examples, see examples/script.
6 */
7
8#ifdef FLECS_SCRIPT
9
10/**
11 * @defgroup c_addons_script Flecs script
12 * @ingroup c_addons
13 * DSL for loading scenes, assets, and configuration.
14 *
15 * @{
16 */
17
18#ifndef FLECS_META
19#define FLECS_META
20#endif
21
22#ifndef FLECS_DOC
23#define FLECS_DOC
24#endif
25
26#ifndef FLECS_PARSER
27#define FLECS_PARSER
28#endif
29
30#ifndef FLECS_SCRIPT_H
31#define FLECS_SCRIPT_H
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#define FLECS_SCRIPT_FUNCTION_ARGS_MAX (16)
38
39/* Must be the same as EcsPrimitiveKindLast */
40#define FLECS_SCRIPT_VECTOR_FUNCTION_COUNT (18)
41
42FLECS_API
44
45/* Relationship added to entities that are created by a template body. The
46 * target of the pair is the template that declares the statement that created
47 * the entity, which for nested templates is the innermost one. The pair is
48 * added to every entity created while instantiating a template body, at any
49 * scope depth (`if`/`else`, `with`, pair scopes, `for` loops and nested entity
50 * scopes), which makes it the way to tell entities that come from a template
51 * apart from entities that are declared by a plain script statement. */
52FLECS_API
53extern ECS_DECLARE(EcsScriptTemplate);
54
55FLECS_API
56extern ECS_DECLARE(EcsScriptTemplateManual);
57
58FLECS_API
59extern ECS_DECLARE(EcsScriptTemplatePending);
60
61FLECS_API
62int ecs_script_template_update(
63 ecs_world_t *world,
64 ecs_entity_t instance,
65 ecs_entity_t template_entity);
66
67FLECS_API
69
70FLECS_API
72
73FLECS_API
75
76FLECS_API
78
79FLECS_API
80extern ECS_DECLARE(EcsScriptVectorType);
81
82/* Script template. */
83typedef struct ecs_script_template_t ecs_script_template_t;
84
86 ecs_entity_t type;
87 void *value;
89
90FLECS_API
92
93/** Script variable. */
94typedef struct ecs_script_var_t {
95 const char *name; /**< Variable name. */
96 ecs_value_t value; /**< Variable value. */
97 const ecs_type_info_t *type_info; /**< Type information. */
98 int32_t sp; /**< Stack pointer. */
99 bool is_const; /**< Whether the variable is constant. */
100 bool owned; /**< Whether the scope owns the value storage. */
102
103/** Script variable scope. */
104typedef struct ecs_script_vars_t {
105 struct ecs_script_vars_t *parent; /**< Parent variable scope. */
106 int32_t sp; /**< Stack pointer for this scope. */
107
108 ecs_hashmap_t var_index; /**< Index for variable name lookups. */
109 ecs_vec_t vars; /**< Vector of variables in this scope. */
110
111 const ecs_world_t *world; /**< The world. */
112 struct ecs_stack_t *stack; /**< Stack allocator for variable storage. */
113 ecs_stack_cursor_t *cursor; /**< Cursor into the stack allocator. */
114 ecs_allocator_t *allocator; /**< General purpose allocator. */
116
117/** Script object. */
118typedef struct ecs_script_t {
119 ecs_world_t *world; /**< The world. */
120 const char *name; /**< Script name. */
121 const char *code; /**< Script source code. */
123
124/** Runtime for executing scripts. */
126
127/** Script component.
128 * This component is added to the entities of managed scripts and templates.
129 */
130typedef struct EcsScript {
131 char *filename; /**< Script filename. */
132 char *code; /**< Script source code. */
133 char *error; /**< Set if script evaluation had errors. */
134 ecs_script_t *script; /**< Parsed script object. */
135 ecs_script_template_t *template_; /**< Only set for template scripts. */
136 ecs_vec_t observers; /**< Observers for referenced components. */
137 ecs_vec_t dyn_observers; /**< Observers for refs resolved at runtime. */
138 bool skip_unknown; /**< Skip unknown components when loading. */
139 bool ir; /**< Evaluate script with IR runtime. */
140
141 /** Code as it was last loaded or saved. For scripts loaded from a file
142 * this is the content of the file when it was last read or written. Used
143 * to detect unsaved changes and changes to the file on disk. */
145
146 /** Previous versions of the code, most recent last (vec<char*>). Updating
147 * the code of the script appends the replaced code. See ecs_script_undo(). */
148 ecs_vec_t undo;
150
151/** Maximum number of versions kept in the undo history of a script. */
152#ifndef FLECS_SCRIPT_UNDO_MAX
153#define FLECS_SCRIPT_UNDO_MAX (64)
154#endif
155
156/** Script function context. */
157typedef struct ecs_function_ctx_t {
158 ecs_world_t *world; /**< The world. */
159 ecs_entity_t function; /**< The function entity. */
160 ecs_entity_t entity; /**< "this" entity (for methods and async functions). */
161 void *ctx; /**< User context. */
163
164/** Script function callback. */
166 const ecs_function_ctx_t *ctx,
167 int32_t argc,
168 const ecs_value_t *argv,
169 ecs_value_t *result);
170
171/** Script vector function callback. */
173 const ecs_function_ctx_t *ctx,
174 int32_t argc,
175 const ecs_value_t *argv,
176 ecs_value_t *result,
177 int32_t elem_count);
178
179/** Function argument type. */
181 const char *name; /**< Parameter name. */
182 ecs_entity_t type; /**< Parameter type. */
183
184 /** Parameter may be omitted by the caller. Optional parameters must come
185 * after the required parameters. The argc argument of the function callback
186 * indicates how many arguments were provided. */
188
189 const char *brief; /**< Short description of the parameter (optional). */
191
192/** Used with ecs_script_parse() and ecs_script_eval(). */
194 ecs_script_runtime_t *runtime; /**< Reusable runtime (optional). */
195
196 /** Skip unknown identifiers. When enabled, scripts that reference unknown
197 * components, component members or functions will still load. This makes
198 * it possible to load scripts for an application without having to load
199 * the application code that registers the components used by the script.
200 *
201 * When skip_unknown is enabled:
202 * - An unresolved identifier that is used as a component or tag creates a
203 * placeholder tag entity with that (scoped) name.
204 * - A value assigned to a placeholder, to a component without reflection
205 * data, or to an unknown member is parsed and discarded.
206 * - An expression that uses an unresolved function or identifier is
207 * discarded. This includes expressions that read an unknown component
208 * (`e[Unknown]`) or an unknown member (`e[Position].unknown`), and
209 * expressions that use a variable that was itself skipped, both directly
210 * and in an interpolated string. When the expression is the condition or
211 * collection of a statement (such as `for`), the statement is skipped.
212 * - A `using` statement with an unresolved identifier is skipped.
213 * - A function with an unresolved parameter or return type is skipped,
214 * which makes calls to that function unresolved expressions.
215 * - Unresolved references in `IsA` expressions, template base types and
216 * template instantiations are still errors, as those are structural.
217 *
218 * Every skipped name is reported once with ecs_warn(). */
220
221 /** Evaluate script with the IR runtime instead of the AST interpreter. */
222 bool ir;
224
225/** Used to capture error output from script evaluation. */
227 char *error; /**< Error message, or NULL if no error. Must be freed by the application. */
228 int32_t line; /**< Line number (1-based) of first error, or 0 if not available. */
229 int32_t column; /**< Column number (1-based) of first error, or 0 if not available. */
231
232#ifdef FLECS_SCRIPT_ASYNC
233#include "script_async.h"
234#endif
235
236/** Const component.
237 * This component describes a const variable that can be used from scripts. The
238 * value of a const variable is folded into expressions that use it.
239 */
240typedef struct EcsScriptConstVar {
241 ecs_value_t value;
242 const ecs_type_info_t *type_info;
244
245/** Mut component.
246 * This component describes a mutable global variable that can be used from
247 * scripts. Unlike a const variable, the value of a mut variable is never folded
248 * into expressions, and scripts that use it are reevaluated when it changes.
249 */
250typedef struct EcsScriptMutVar {
251 ecs_value_t value;
252 const ecs_type_info_t *type_info;
254
256 ecs_entity_t return_type;
257 ecs_vec_t params; /* vec<ecs_script_parameter_t> */
259#ifdef FLECS_SCRIPT_ASYNC
260 ecs_async_function_callback_t async_callback;
261 ecs_async_function_cancel_t async_cancel;
262#endif
263 ecs_vector_function_callback_t vector_callbacks[FLECS_SCRIPT_VECTOR_FUNCTION_COUNT];
264 void *ctx;
265 void *binding_ctx;
266 ecs_ctx_free_t binding_ctx_free;
267};
268
269/** Function component.
270 * This component describes a function that can be called from a script.
271 */
273
274/** Method component.
275 * This component describes a method that can be called from a script. Methods
276 * are functions that can be called on instances of a type. A method entity is
277 * stored in the scope of the type it belongs to.
278 */
280
281/* Parsing and running scripts */
282
283/** Parse script.
284 * This operation parses a script and returns a script object upon success. To
285 * run the script, call ecs_script_eval().
286 *
287 * When the result parameter is not NULL, the script will capture errors and
288 * return them in the output struct. If result.error is set, it must be freed
289 * by the application.
290 *
291 * @param world The world.
292 * @param name Name of the script (typically a file or module name).
293 * @param code The script code.
294 * @param desc Parameters for script runtime.
295 * @param result Output of script evaluation.
296 * @return Script object if success, NULL if failed.
297*/
298FLECS_API
300 ecs_world_t *world,
301 const char *name,
302 const char *code,
303 const ecs_script_eval_desc_t *desc,
305
306/** Evaluate script.
307 * This operation evaluates (runs) a parsed script.
308 *
309 * When the result parameter is not NULL, the script will capture errors and
310 * return them in the output struct. If result.error is set, it must be freed
311 * by the application.
312 *
313 * @param script The script.
314 * @param desc Parameters for script runtime.
315 * @param result Output of script evaluation (optional).
316 * @return Zero if success, non-zero if failed.
317*/
318FLECS_API
320 const ecs_script_t *script,
321 const ecs_script_eval_desc_t *desc,
323
324/** Free script.
325 * This operation frees a script object.
326 *
327 * Templates created by the script rely upon resources in the script object,
328 * and for that reason keep the script alive until all templates created by the
329 * script are deleted.
330 *
331 * @param script The script.
332 */
333FLECS_API
336
337/** Parse script.
338 * This parses a script and instantiates the entities in the world.
339 * This operation is the equivalent to doing:
340 *
341 * @code
342 * ecs_script_t *script = ecs_script_parse(world, name, code);
343 * ecs_script_eval(script);
344 * ecs_script_free(script);
345 * @endcode
346 *
347 * @param world The world.
348 * @param name The script name (typically the file).
349 * @param code The script.
350 * @param result Output of script evaluation (optional).
351 * @return Zero if success, non-zero otherwise.
352 */
353FLECS_API
355 ecs_world_t *world,
356 const char *name,
357 const char *code,
359
360/** Parse script and evaluate with options.
361 * Same as ecs_script_run(), but accepts a descriptor that configures parsing
362 * and evaluation, such as skip_unknown or the runtime (AST or IR) to use.
363 *
364 * @param world The world.
365 * @param name The script name (typically the file).
366 * @param code The script.
367 * @param desc Parse and evaluation options (optional).
368 * @param result Output of script evaluation (optional).
369 * @return Zero if success, non-zero if failed.
370 */
371FLECS_API
373 ecs_world_t *world,
374 const char *name,
375 const char *code,
376 const ecs_script_eval_desc_t *desc,
378
379/** Parse script file.
380 * This parses a script file and instantiates the entities in the world. This
381 * operation is equivalent to loading the file contents and passing it to
382 * ecs_script_run().
383 *
384 * @param world The world.
385 * @param filename The script file name.
386 * @return Zero if success, non-zero if failed.
387 */
388FLECS_API
390 ecs_world_t *world,
391 const char *filename);
392
393/** Parse script file and evaluate with options.
394 * Same as ecs_script_run_file(), but accepts a descriptor that configures
395 * parsing and evaluation.
396 *
397 * @param world The world.
398 * @param filename The script file name.
399 * @param desc Parse and evaluation options (optional).
400 * @return Zero if success, non-zero if failed.
401 */
402FLECS_API
404 ecs_world_t *world,
405 const char *filename,
406 const ecs_script_eval_desc_t *desc);
407
408/** Convert script IR to string.
409 * Compiles the script to IR if it hasn't been compiled yet, and returns a
410 * human readable listing of the instructions.
411 *
412 * @param script The script.
413 * @return The IR listing. Must be freed with ecs_os_free.
414 */
415FLECS_API
417 const ecs_script_t *script);
418
419#ifdef FLECS_SCRIPT_IR_PROFILE
420/** Reset IR runtime profiling counters (only available when compiled with
421 * FLECS_SCRIPT_IR_PROFILE). */
422FLECS_API
423void ecs_script_ir_profile_reset(void);
424
425/** Get IR runtime profiling counters as string (only available when compiled
426 * with FLECS_SCRIPT_IR_PROFILE). Must be freed with ecs_os_free. */
427FLECS_API
428char* ecs_script_ir_profile_str(void);
429#endif
430
431/** Create runtime for script.
432 * A script runtime is a container for any data created during script
433 * evaluation. By default, calling ecs_script_run() or ecs_script_eval() will
434 * create a runtime on the spot. A runtime can be created in advance and reused
435 * across multiple script evaluations to improve performance.
436 *
437 * When scripts are evaluated on multiple threads, each thread should have its
438 * own script runtime.
439 *
440 * A script runtime must be deleted with ecs_script_runtime_free().
441 *
442 * @return A new script runtime.
443 */
444FLECS_API
446
447/** Free script runtime.
448 * This operation frees a script runtime created by ecs_script_runtime_new().
449 *
450 * @param runtime The runtime to free.
451 */
452FLECS_API
454 ecs_script_runtime_t *runtime);
455
456/** Convert script AST to string.
457 * This operation converts the script abstract syntax tree to a string, which
458 * can be used to debug a script.
459 *
460 * @param script The script.
461 * @param buf The buffer to write to.
462 * @param colors Whether to include ANSI color codes in the output.
463 * @return Zero if success, non-zero if failed.
464 */
465FLECS_API
468 ecs_strbuf_t *buf,
469 bool colors);
470
471/** Convert script AST to string.
472 * This operation converts the script abstract syntax tree to a string, which
473 * can be used to debug a script.
474 *
475 * @param script The script.
476 * @param colors Whether to include ANSI color codes in the output.
477 * @return The string if success, NULL if failed.
478 */
479FLECS_API
482 bool colors);
483
484
485/* Source preserving script edits */
486
487/** Source location of a script statement.
488 * Returned by ecs_script_entity_source(). The offset and length are byte
489 * offsets into ecs_script_t::code.
490 */
491typedef struct ecs_script_source_t {
492 int32_t offset; /**< Offset of the first character of the statement. */
493 int32_t length; /**< Number of bytes occupied by the statement. */
494 int32_t line; /**< Line of the first character (1 based). */
495 int32_t column; /**< Column of the first character (1 based). */
496 bool has_scope; /**< Whether the statement is followed by a { } scope. */
497
498 /** Set when the statement is inside the body of a `template` statement.
499 * When set, this is the template entity that the body belongs to, and the
500 * statement is shared by every instance of that template: editing it
501 * changes all instances. Zero for regular entity statements. */
504
505/** Find the statement that declares an entity.
506 * This operation returns the source location of the entity statement that
507 * declared an entity. The script must have been evaluated at least once, as
508 * the mapping from entity to statement is established during evaluation.
509 *
510 * Entities that were created by instantiating a `template` declared by this
511 * script are resolved to the statement in the template body that created them.
512 * Because a template body statement is shared by all instances of the template,
513 * the same statement is returned for every instance, and
514 * ecs_script_source_t::template_ is set to the template entity. The template
515 * must be declared by this script; when a script instantiates a template that
516 * is declared by another script (for example a template from an included file),
517 * the body entities are reported by the script that declares the template, not
518 * by the script that instantiates it.
519 *
520 * The operation returns false when the entity was not created by an entity
521 * statement of this script. This is the case for:
522 *
523 * - entities that were not created by a script
524 * - entities created by a different script (an `include` statement evaluates
525 * the included file as a separate script object, so entities created by an
526 * included file are never reported by the including script)
527 * - entities created inside a `for` loop or a function body, also when the
528 * `for` loop is part of a template body
529 * - entities created by a template body statement with a computed name
530 * - entities created by a "new" expression
531 *
532 * An entity that carries the (EcsScriptTemplate, *) pair is never reported as a
533 * plain (non-template) statement, also not by the script that instantiates the
534 * template.
535 *
536 * When an entity is declared by more than one statement, the location of the
537 * first declaration is returned.
538 *
539 * The returned offsets stay valid until the script is freed or reparsed.
540 *
541 * @param script The script.
542 * @param entity The entity to find.
543 * @param source Out parameter with the source location (optional).
544 * @return True if the entity is declared by this script, false if not.
545 */
546FLECS_API
548 const ecs_script_t *script,
549 ecs_entity_t entity,
550 ecs_script_source_t *source);
551
552/** Find the managed script that declares an entity.
553 * This operation returns the entity of the managed script (see ecs_script())
554 * whose source code contains the statement that created the entity. The
555 * returned script entity is the one to use with ecs_script_entity_source() and
556 * ecs_script_edits_new():
557 *
558 * @code
559 * ecs_entity_t s = ecs_script_entity_owner(world, e);
560 * const EcsScript *sc = ecs_get(world, s, EcsScript);
561 * ecs_script_edits_t *edits = ecs_script_edits_new(sc->script);
562 * @endcode
563 *
564 * For entities that were created by a regular entity statement this is the
565 * script that created the entity. For entities that were created by a template
566 * body this is the script that *declares* the template, which is not
567 * necessarily the script that instantiates it.
568 *
569 * The operation returns 0 when the entity is not editable, which is the case
570 * when the entity was not created by a script, when the script that created it
571 * is not managed (see ecs_script_parse()), or when the statement that created
572 * the entity cannot be attributed to the entity (see
573 * ecs_script_entity_source()).
574 *
575 * @param world The world.
576 * @param entity The entity to find.
577 * @return The managed script entity, or 0 if the entity is not editable.
578 */
579FLECS_API
581 const ecs_world_t *world,
582 ecs_entity_t entity);
583
584/** Set of pending edits for a script.
585 * See ecs_script_edits_new().
586 */
588
589/** Create an edit set for a script.
590 * An edit set collects changes that are keyed by entity id, and turns them into
591 * new script source code with ecs_script_edits_apply(). Only the edited
592 * statements change; all other text (comments, whitespace, layout, expressions,
593 * include statements) is preserved byte for byte.
594 *
595 * The script must be evaluated before edits can be added, and must outlive the
596 * edit set.
597 *
598 * Edits are resolved to a source code span when they are recorded, not when
599 * they are applied. The entity is only used to find the statement at that
600 * moment; afterwards the recorded edit no longer depends on it. This means an
601 * edit set can outlive the entities it was recorded for, but it also means
602 * that a delete must be recorded *before* the entity is deleted:
603 *
604 * @code
605 * ecs_script_edits_delete(edits, e);
606 * ecs_delete(world, e);
607 * @endcode
608 *
609 * Recording an edit for an entity that is no longer alive fails, as the
610 * statement can no longer be found.
611 *
612 * A recorded edit can be dropped again with ecs_script_edits_clear(), which
613 * makes it possible to use a single edit set as an undo/redo buffer for an
614 * editing session.
615 *
616 * An edit set must be deleted with ecs_script_edits_free().
617 *
618 * @param script The script to edit.
619 * @return A new edit set, or NULL if the script is invalid.
620 */
621FLECS_API
624
625/** Free an edit set.
626 *
627 * @param edits The edit set.
628 */
629FLECS_API
631 ecs_script_edits_t *edits);
632
633/** Set a component value on an entity.
634 * If the entity scope already contains a statement for the component, only the
635 * value expression of that statement is replaced. The style of the existing
636 * initializer is preserved:
637 *
638 * - a named initializer ("{x: 10, y: 20}") stays named
639 * - a positional initializer ("{10, 20}") stays positional
640 * - an empty initializer ("{}") becomes positional
641 * - any other value form (a plain expression, a collection initializer, a match
642 * expression) is replaced with the default serialized form
643 *
644 * All members of the component are written, in the order in which they are
645 * defined by the type. Floating point members are written as the shortest
646 * decimal string that parses back to the same value ("1.2345" for a float with
647 * value 1.2345f, "1" for a float with value 1.0f), so values roundtrip without
648 * accumulating digits.
649 *
650 * When the entity was created by a template body statement (see
651 * ecs_script_entity_source()) the statement in the template body is edited,
652 * which changes the value for every instance of the template. Any expression
653 * that the body used for the value (such as a prop or const reference) is
654 * replaced by the literal value that is passed to this operation.
655 *
656 * If the entity scope does not contain a statement for the component, a new
657 * "Component: {...}" statement is appended to the end of the entity scope,
658 * using the indentation of the other statements in the scope (or the
659 * indentation of the entity statement plus four spaces when the scope is
660 * empty). When the entity statement has no scope, a scope is added.
661 *
662 * If the entity scope contains more than one statement for the component, the
663 * last statement is replaced. If the entity is declared by more than one
664 * statement, the first declaration is edited.
665 *
666 * Only statements in the scope of the entity itself are considered. A value
667 * that the entity inherits from an enclosing `with` statement is not modified;
668 * setting such a component adds a statement to the entity scope that overrides
669 * the `with` value.
670 *
671 * The component is written with the shortest name that resolves to the same
672 * component given the `using` and `module` statements of the script.
673 *
674 * @param edits The edit set.
675 * @param entity The entity to edit.
676 * @param component The component (or pair) to set.
677 * @param value Pointer to the component value.
678 * @return Zero if success, non-zero if failed.
679 */
680FLECS_API
682 ecs_script_edits_t *edits,
683 ecs_entity_t entity,
684 ecs_id_t component,
685 const void *value);
686
687/** Set a component value on an entity from an expression string.
688 * Same as ecs_script_edits_set(), but instead of serializing a value, the
689 * provided expression is written to the script verbatim. The expression is not
690 * validated.
691 *
692 * @param edits The edit set.
693 * @param entity The entity to edit.
694 * @param component The component (or pair) to set.
695 * @param expr The value expression (for example "{10, 20}").
696 * @return Zero if success, non-zero if failed.
697 */
698FLECS_API
700 ecs_script_edits_t *edits,
701 ecs_entity_t entity,
702 ecs_id_t component,
703 const char *expr);
704
705/** Remove a component from an entity.
706 * This removes the statement that adds the component (or tag) to the entity,
707 * including the line(s) the statement occupies. If the entity scope contains
708 * more than one statement for the component, the last statement is removed.
709 *
710 * The operation returns zero when the entity does not have a statement for the
711 * component, as the resulting source has the requested state.
712 *
713 * @param edits The edit set.
714 * @param entity The entity to edit.
715 * @param component The component (or pair) to remove.
716 * @return Zero if success, non-zero if failed.
717 */
718FLECS_API
720 ecs_script_edits_t *edits,
721 ecs_entity_t entity,
722 ecs_id_t component);
723
724/** Delete an entity.
725 * This removes the entity statement, its scope, and the line(s) the statement
726 * occupies. Comments that precede the statement are preserved. A trailing
727 * comment on the last line of the statement is removed together with the line.
728 *
729 * When the removed lines are surrounded by blank lines (where the start of the
730 * file, the opening brace of the enclosing scope, the closing brace of the
731 * enclosing scope and the end of the file count as blank), one of the blank
732 * lines is removed as well, so that the statements around the deleted statement
733 * stay separated by exactly one blank line.
734 *
735 * Other edits that fall inside the span of a deleted entity (such as edits to
736 * child entities) are absorbed by the deletion.
737 *
738 * When the entity was created by a template body statement (see
739 * ecs_script_entity_source()) the statement in the template body is deleted,
740 * which removes the entity from every instance of the template.
741 *
742 * The operation only records the source code span of the statement, it does
743 * not delete the entity. The edit must be recorded while the entity is still
744 * alive; the recorded edit remains valid after the entity is deleted with
745 * ecs_delete(). See ecs_script_edits_new().
746 *
747 * @param edits The edit set.
748 * @param entity The entity to delete.
749 * @return Zero if success, non-zero if failed.
750 */
751FLECS_API
753 ecs_script_edits_t *edits,
754 ecs_entity_t entity);
755
756/** Remove a recorded edit from an edit set.
757 * Edits are keyed by entity and component. This operation removes the edit
758 * that was recorded for the provided key, which undoes the effect that the
759 * edit would have had on ecs_script_edits_apply().
760 *
761 * Pass 0 for the component to clear the edit recorded by
762 * ecs_script_edits_delete(). Pass a component (or pair) to clear the edit
763 * recorded by ecs_script_edits_set(), ecs_script_edits_set_expr() or
764 * ecs_script_edits_remove() for that component.
765 *
766 * The entity is only used as a key. It does not have to be alive, which means
767 * an edit that was recorded before the entity was deleted can still be
768 * cleared afterwards.
769 *
770 * @param edits The edit set.
771 * @param entity The entity the edit was recorded for.
772 * @param component The component the edit was recorded for, or 0 for a delete.
773 * @return Zero if an edit was removed, non-zero if no edit was recorded.
774 */
775FLECS_API
777 ecs_script_edits_t *edits,
778 ecs_entity_t entity,
779 ecs_id_t component);
780
781/** Return the number of recorded edits in an edit set.
782 * Edits are keyed by entity and component, which means that recording an edit
783 * twice for the same key does not increase the count.
784 *
785 * @param edits The edit set.
786 * @return The number of recorded edits.
787 */
788FLECS_API
790 const ecs_script_edits_t *edits);
791
792/** Apply an edit set.
793 * This operation returns new script source code with the edits applied. The
794 * operation does not modify the script or the edit set, which means that
795 * applying the same edit set twice returns the same text.
796 *
797 * The operation returns NULL when two edits overlap in a way that cannot be
798 * resolved.
799 *
800 * @param edits The edit set.
801 * @return The new source code, must be freed with ecs_os_free(). NULL if
802 * failed.
803 */
804FLECS_API
806 const ecs_script_edits_t *edits);
807
808
809/* Managed scripts (script associated with entity that outlives the function) */
810
811/** Used with ecs_script_init(). */
812typedef struct ecs_script_desc_t {
813 ecs_entity_t entity; /**< Set to customize entity handle associated with script. */
814 const char *filename; /**< Set to load script from file. */
815 const char *code; /**< Set to parse script from string. */
816 bool skip_unknown; /**< Skip unknown identifiers (see ecs_script_eval_desc_t::skip_unknown). */
817 bool ir; /**< Evaluate script with IR runtime. */
819
820/** Load managed script.
821 * A managed script tracks which entities it creates, and keeps those entities
822 * synchronized when the contents of the script are updated. When the script is
823 * updated, entities that are no longer in the new version will be deleted.
824 *
825 * This feature is experimental.
826 *
827 * @param world The world.
828 * @param desc Script descriptor.
829 * @return The script entity.
830 */
831FLECS_API
833 ecs_world_t *world,
834 const ecs_script_desc_t *desc);
835
836#define ecs_script(world, ...)\
837 ecs_script_init(world, &(ecs_script_desc_t) __VA_ARGS__)
838
839/** Update script with new code.
840 *
841 * @param world The world.
842 * @param script The script entity.
843 * @param instance A template instance (optional).
844 * @param code The script code.
845 * @return Zero if success, non-zero if failed.
846 */
847FLECS_API
849 ecs_world_t *world,
851 ecs_entity_t instance,
852 const char *code);
853
854/** Reload script from new code or from the file it was loaded from.
855 * This operation re-runs a managed script and reconciles the entities it owns:
856 * entities that the new version no longer defines are deleted, entities that
857 * changed are updated and entities that were added are created.
858 *
859 * When code is NULL the script is reloaded from EcsScript::filename, which is
860 * set when the script is created with ecs_script_desc_t::filename. When the
861 * script has no filename the operation fails.
862 *
863 * Unlike ecs_script_update(), the new code is parsed before the entities of the
864 * old version are deleted. When parsing fails the world is left untouched and
865 * the parser error is stored in EcsScript::error.
866 *
867 * @param world The world.
868 * @param script The script entity.
869 * @param code The script code, or NULL to reload from file.
870 * @return Zero if success, non-zero if failed.
871 */
872FLECS_API
874 ecs_world_t *world,
876 const char *code);
877
878/** Undo the last change to the code of a managed script.
879 * Each time the code of a managed script is replaced with different code (for
880 * example by ecs_script_update() or ecs_script_reload()), the previous code is
881 * added to the undo history of the script (see EcsScript::undo). This operation
882 * removes the most recent version from the undo history and reloads the
883 * script with it. The undo history holds up to FLECS_SCRIPT_UNDO_MAX versions.
884 *
885 * @param world The world.
886 * @param script The script entity.
887 * @return Zero if success, non-zero if the history is empty or the reload
888 * failed.
889 */
890FLECS_API
892 ecs_world_t *world,
894
895/** Clear all entities associated with script.
896 *
897 * @param world The world.
898 * @param script The script entity.
899 * @param instance The script instance.
900 */
901FLECS_API
903 ecs_world_t *world,
905 ecs_entity_t instance);
906
907/** Update the code of a managed script with the current values of its entities.
908 * This operation iterates the entities created by a managed script, and for
909 * each component statement in the scope of an entity statement compares the
910 * value the statement assigns with the current value of the component. When the
911 * values differ, the statement is updated with ecs_script_edits_set(), which
912 * preserves the rest of the source code.
913 *
914 * Only statements with a constant value are compared. A statement whose value
915 * depends on a variable, a function call or another non-constant expression is
916 * left untouched. Statements in template bodies, components that the entity
917 * no longer has and components that are added or removed after evaluation are
918 * ignored.
919 *
920 * When there are changes, the script is reloaded with the new code (see
921 * ecs_script_reload()), which updates EcsScript::code. When there are no
922 * changes the script is left untouched.
923 *
924 * @param world The world.
925 * @param script The script entity.
926 * @return 1 if the script was updated, 0 if there were no changes, -1 if
927 * failed.
928 */
929FLECS_API
931 ecs_world_t *world,
933
934/** Save the code of a managed script to the file it was loaded from.
935 * This operation writes EcsScript::code to EcsScript::filename, and updates
936 * EcsScript::saved_code. When the script was not loaded from a file the
937 * operation does nothing.
938 *
939 * @param world The world.
940 * @param script The script entity.
941 * @return Zero if success, non-zero if failed.
942 */
943FLECS_API
945 ecs_world_t *world,
947
948
949/* Script variables */
950
951/** Create new variable scope.
952 * Create root variable scope. A variable scope contains one or more variables.
953 * Scopes can be nested, which allows variables in different scopes to have the
954 * same name. Variables from parent scopes will be shadowed by variables in
955 * child scopes with the same name.
956 *
957 * Use the `ecs_script_vars_push()` and `ecs_script_vars_pop()` functions to
958 * push and pop variable scopes.
959 *
960 * When a variable contains allocated resources (e.g., a string), its resources
961 * will be freed when `ecs_script_vars_pop()` is called on the scope, the
962 * ecs_script_vars_t::type_info field is initialized for the variable, and
963 * `ecs_type_info_t::hooks::dtor` is set.
964 *
965 * @param world The world.
966 * @return The new root variable scope.
967 */
968FLECS_API
970 ecs_world_t *world);
971
972/** Free variable scope.
973 * Free root variable scope. The provided scope should not have a parent. This
974 * operation calls `ecs_script_vars_pop()` on the scope.
975 *
976 * @param vars The variable scope.
977 */
978FLECS_API
980 ecs_script_vars_t *vars);
981
982/** Push new variable scope.
983 *
984 * Scopes created with ecs_script_vars_push() must be cleaned up with
985 * ecs_script_vars_pop().
986 *
987 * If the stack and allocator arguments are left to NULL, their values will be
988 * copied from the parent.
989 *
990 * @param parent The parent scope (provide NULL for root scope).
991 * @return The new variable scope.
992 */
993FLECS_API
995 ecs_script_vars_t *parent);
996
997/** Pop variable scope.
998 * This frees up the resources for a variable scope. The scope must be at the
999 * top of a vars stack. Calling ecs_script_vars_pop() on a scope that is not the
1000 * last scope causes undefined behavior.
1001 *
1002 * @param vars The scope to free.
1003 * @return The parent scope.
1004 */
1005FLECS_API
1007 ecs_script_vars_t *vars);
1008
1009/** Declare a variable.
1010 * This operation declares a new variable in the current scope. If a variable
1011 * with the specified name already exists, the operation will fail.
1012 *
1013 * This operation does not allocate storage for the variable. This is done to
1014 * allow for variables that point to existing storage, which prevents having
1015 * to copy existing values to a variable scope.
1016 *
1017 * @param vars The variable scope.
1018 * @param name The variable name.
1019 * @return The new variable, or NULL if the operation failed.
1020 */
1021FLECS_API
1023 ecs_script_vars_t *vars,
1024 const char *name);
1025
1026/** Define a variable.
1027 * This operation calls `ecs_script_vars_declare()` and allocates storage for
1028 * the variable. If the type has a ctor, it will be called on the new storage.
1029 *
1030 * The scope's stack allocator will be used to allocate the storage. After
1031 * `ecs_script_vars_pop()` is called on the scope, the variable storage will no
1032 * longer be valid.
1033 *
1034 * The operation will fail if the type argument is not a type.
1035 *
1036 * @param vars The variable scope.
1037 * @param name The variable name.
1038 * @param type The variable type.
1039 * @return The new variable, or NULL if the operation failed.
1040 */
1041FLECS_API
1043 ecs_script_vars_t *vars,
1044 const char *name,
1045 ecs_entity_t type);
1046
1047#define ecs_script_vars_define(vars, name, type)\
1048 ecs_script_vars_define_id(vars, name, ecs_id(type))
1049
1050/** Lookup a variable.
1051 * This operation looks up a variable in the current scope. If the variable
1052 * can't be found in the current scope, the operation will recursively search
1053 * the parent scopes.
1054 *
1055 * @param vars The variable scope.
1056 * @param name The variable name.
1057 * @return The variable, or NULL if one with the provided name does not exist.
1058 */
1059FLECS_API
1061 const ecs_script_vars_t *vars,
1062 const char *name);
1063
1064/** Lookup a variable by stack pointer.
1065 * This operation provides a faster way to lookup variables that are always
1066 * declared in the same order in a ecs_script_vars_t scope.
1067 *
1068 * The stack pointer of a variable can be obtained from the ecs_script_var_t
1069 * type. The provided frame offset must be valid for the provided variable
1070 * stack. If the frame offset is not valid, this operation will panic.
1071 *
1072 * @param vars The variable scope.
1073 * @param sp The stack pointer to the variable.
1074 * @return The variable.
1075 */
1076FLECS_API
1078 const ecs_script_vars_t *vars,
1079 int32_t sp);
1080
1081/** Print variables.
1082 * This operation prints all variables in the vars scope and parent scopes.
1083 *
1084 * @param vars The variable scope.
1085 */
1086FLECS_API
1088 const ecs_script_vars_t *vars);
1089
1090/** Preallocate space for variables.
1091 * This operation preallocates space for the specified number of variables. This
1092 * is a performance optimization only, and is not necessary before declaring
1093 * variables in a scope.
1094 *
1095 * @param vars The variable scope.
1096 * @param count The number of variables to preallocate space for.
1097 */
1098FLECS_API
1100 ecs_script_vars_t *vars,
1101 int32_t count);
1102
1103/** Convert iterator to vars.
1104 * This operation converts an iterator to a variable array. This allows for
1105 * using iterator results in expressions. The operation only converts a
1106 * single result at a time, and does not progress the iterator.
1107 *
1108 * Iterator fields with data will be made available as variables with as name
1109 * the field index (e.g., "$1"). The operation does not check if reflection data
1110 * is registered for a field type. If no reflection data is registered for the
1111 * type, using the field variable in expressions will fail.
1112 *
1113 * Field variables will only contain single elements, even if the iterator
1114 * returns component arrays. The offset parameter can be used to specify which
1115 * element in the component arrays to return. The offset parameter must be
1116 * smaller than it->count.
1117 *
1118 * The operation will create a variable for query variables that contain a
1119 * single entity.
1120 *
1121 * The operation will attempt to use existing variables. If a variable does not
1122 * yet exist, the operation will create it. If an existing variable exists with
1123 * a mismatching type, the operation will fail.
1124 *
1125 * Accessing variables after progressing the iterator or after the iterator is
1126 * destroyed will result in undefined behavior.
1127 *
1128 * If vars contains a variable that is not present in the iterator, the variable
1129 * will not be modified.
1130 *
1131 * @param it The iterator to convert to variables.
1132 * @param vars The variables to write to.
1133 * @param offset The offset to the current element.
1134 */
1135FLECS_API
1137 const ecs_iter_t *it,
1138 ecs_script_vars_t *vars,
1139 int offset);
1140
1141
1142/* Standalone expression evaluation */
1143
1144/** Used with ecs_expr_run(). */
1145typedef struct ecs_expr_eval_desc_t {
1146 const char *name; /**< Script name. */
1147 const char *expr; /**< Full expression string. */
1148 const ecs_script_vars_t *vars; /**< Variables accessible in expression. */
1149 ecs_entity_t type; /**< Type of parsed value (optional). */
1150 ecs_entity_t (*lookup_action)( /**< Function for resolving entity identifiers. */
1151 const ecs_world_t*,
1152 const char *value,
1153 void *ctx);
1154 void *lookup_ctx; /**< Context passed to lookup function. */
1155
1156 /** Disable constant folding (slower evaluation, faster parsing). */
1158
1159 /** This option instructs the expression runtime to lookup variables by
1160 * stack pointer instead of by name, which improves performance. Only enable
1161 * when provided variables are always declared in the same order. */
1163
1164 /** Allow for unresolved identifiers when parsing. Useful when entities can
1165 * be created in between parsing and evaluating. */
1167
1168 /** When the expression is an initializer, only assign the members that
1169 * the initializer sets. Other members keep the value they had in the
1170 * output value, the same as a partial component assignment in a script
1171 * ("Position = {x: 10}"). */
1173
1174 ecs_script_runtime_t *runtime; /**< Reusable runtime (optional). */
1175
1176 void *script_visitor; /**< For internal usage. */
1178
1179/** Run expression.
1180 * This operation runs an expression and stores the result in the provided
1181 * value. If the value contains a type that is different from the type of the
1182 * expression, the expression will be cast to the value.
1183 *
1184 * If the provided value for value.ptr is NULL, the value must be freed with
1185 * ecs_ptr_free() afterwards.
1186 *
1187 * @param world The world.
1188 * @param ptr The pointer to the expression to parse.
1189 * @param value The value containing type and pointer to write to.
1190 * @param desc Configuration parameters for the parser.
1191 * @return Pointer to the character after the last one read, or NULL if failed.
1192 */
1193FLECS_API
1194const char* ecs_expr_run(
1195 ecs_world_t *world,
1196 const char *ptr,
1197 ecs_value_t *value,
1198 const ecs_expr_eval_desc_t *desc);
1199
1200/** Parse expression.
1201 * This operation parses an expression and returns an object that can be
1202 * evaluated multiple times with ecs_expr_eval().
1203 *
1204 * @param world The world.
1205 * @param expr The expression string.
1206 * @param desc Configuration parameters for the parser.
1207 * @return A script object if parsing is successful, NULL if parsing failed.
1208 */
1209FLECS_API
1211 ecs_world_t *world,
1212 const char *expr,
1213 const ecs_expr_eval_desc_t *desc);
1214
1215/** Evaluate expression.
1216 * This operation evaluates an expression parsed with ecs_expr_parse()
1217 * and stores the result in the provided value. If the value contains a type
1218 * that is different from the type of the expression, the expression will be
1219 * cast to the value.
1220 *
1221 * If the provided value for value.ptr is NULL, the value must be freed with
1222 * ecs_ptr_free() afterwards.
1223 *
1224 * @param script The script containing the expression.
1225 * @param value The value in which to store the expression result.
1226 * @param desc Configuration parameters for the parser.
1227 * @return Zero if successful, non-zero if failed.
1228 */
1229FLECS_API
1231 const ecs_script_t *script,
1232 ecs_value_t *value,
1233 const ecs_expr_eval_desc_t *desc);
1234
1235/** Evaluate interpolated expressions in string.
1236 * This operation evaluates expressions in a string, and replaces them with
1237 * their evaluated result. Supported expression formats are:
1238 * - $variable_name
1239 * - {expression}
1240 *
1241 * The $, { and } characters can be escaped with a backslash (\‍).
1242 *
1243 * @param world The world.
1244 * @param str The string to evaluate.
1245 * @param vars The variables to use for evaluation.
1246 * @return String with interpolated expressions, or NULL if failed.
1247 */
1248FLECS_API
1250 ecs_world_t *world,
1251 const char *str,
1252 const ecs_script_vars_t *vars);
1253
1254
1255/* Global const variables */
1256
1257/** Used with ecs_const_var_init(). */
1258typedef struct ecs_const_var_desc_t {
1259 /** Variable name. */
1260 const char *name;
1261
1262 /** Variable parent (namespace). */
1264
1265 /** Variable type. */
1267
1268 /** Pointer to value of variable. The value will be copied to an internal
1269 * storage and does not need to be kept alive. */
1270 void *value;
1272
1273/** Create a const variable that can be accessed by scripts.
1274 *
1275 * @param world The world.
1276 * @param desc Const var parameters.
1277 * @return The const var, or 0 if failed.
1278 */
1279FLECS_API
1281 ecs_world_t *world,
1282 ecs_const_var_desc_t *desc);
1283
1284#define ecs_const_var(world, ...)\
1285 ecs_const_var_init(world, &(ecs_const_var_desc_t)__VA_ARGS__)
1286
1287
1288/** Return the value for a const variable.
1289 * This returns the value for a const variable that is created either with
1290 * ecs_const_var_init(), or in a script with "export const v = ...".
1291 *
1292 * @param world The world.
1293 * @param var The const variable.
1294 * @return The value of the const variable.
1295 */
1296FLECS_API
1298 const ecs_world_t *world,
1299 ecs_entity_t var);
1300
1301/** Return pointer to the value of a const variable.
1302 * This operation returns the value of a const variable, casted to the specified
1303 * type. If the type is equal to that of the const variable, no cast is
1304 * performed. If the variable cannot be casted to the specified type, the
1305 * operation will throw an error.
1306 *
1307 * The returned value is owned by the caller. If the returned value contains
1308 * allocated memory, this needs to be freed by the caller.
1309 *
1310 * This operation is intended to be used by the ecs_const_var_get_t macro.
1311 *
1312 * @param world The world.
1313 * @param name The name of the const variable.
1314 * @param type The requested type.
1315 * @param size The size of the requested type.
1316 * @param out Storage for the value of the const variable.
1317 * @return Pointer to the value of the const variable.
1318 */
1319FLECS_API
1321 const ecs_world_t *world,
1322 const char *name,
1323 ecs_entity_t type,
1324 ecs_size_t size,
1325 void *out);
1326
1327/** Return pointer to the value of a const variable.
1328 * This operation returns the value of a const variable, casted to the specified
1329 * type. If the type is equal to that of the const variable, no cast is
1330 * performed. If the variable cannot be casted to the specified type, the
1331 * operation will throw an error.
1332 *
1333 * The returned value is owned by the caller. If the returned value contains
1334 * allocated memory, this needs to be freed by the caller.
1335 *
1336 * When the operation fails, a zero initialized value is returned.
1337 *
1338 * @param world The world.
1339 * @param name The name of the const variable.
1340 * @param T The requested type.
1341 * @return The value of the const variable.
1342 */
1343#define ecs_const_var_get_t(world, name, T)\
1344 (*ECS_CAST(T*, ecs_const_var_get_w_type(\
1345 world, name, ecs_id(T), ECS_SIZEOF(T), &(T){0})))
1346
1347
1348/* Global mut variables */
1349
1350/** Used with ecs_mut_var_init(). */
1351typedef struct ecs_mut_var_desc_t {
1352 /** Variable name. */
1353 const char *name;
1354
1355 /** Variable parent (namespace). */
1357
1358 /** Variable type. */
1360
1361 /** Pointer to value of variable. The value will be copied to an internal
1362 * storage and does not need to be kept alive. */
1363 void *value;
1365
1366/** Create a mut variable that can be accessed by scripts.
1367 * Unlike a const variable the value of a mut variable is never folded into
1368 * expressions, which means scripts that use it are reevaluated when the value
1369 * changes.
1370 *
1371 * @param world The world.
1372 * @param desc Mut var parameters.
1373 * @return The mut var, or 0 if failed.
1374 */
1375FLECS_API
1377 ecs_world_t *world,
1378 ecs_mut_var_desc_t *desc);
1379
1380#define ecs_mut_var(world, ...)\
1381 ecs_mut_var_init(world, &(ecs_mut_var_desc_t)__VA_ARGS__)
1382
1383
1384/** Return the value for a mut variable.
1385 * This returns the value for a mut variable that is created either with
1386 * ecs_mut_var_init(), or in a script with "export mut v = ...".
1387 *
1388 * @param world The world.
1389 * @param var The mut variable.
1390 * @return The value of the mut variable.
1391 */
1392FLECS_API
1394 const ecs_world_t *world,
1395 ecs_entity_t var);
1396
1397/** Return pointer to the value of a mut variable.
1398 * This operation returns the value of a mut variable, casted to the specified
1399 * type. If the type is equal to that of the mut variable, no cast is
1400 * performed. If the variable cannot be casted to the specified type, the
1401 * operation will throw an error.
1402 *
1403 * The returned value is owned by the caller. If the returned value contains
1404 * allocated memory, this needs to be freed by the caller.
1405 *
1406 * This operation is intended to be used by the ecs_mut_var_get_t macro.
1407 *
1408 * @param world The world.
1409 * @param name The name of the mut variable.
1410 * @param type The requested type.
1411 * @param size The size of the requested type.
1412 * @param out Storage for the value of the mut variable.
1413 * @return Pointer to the value of the mut variable.
1414 */
1415FLECS_API
1417 const ecs_world_t *world,
1418 const char *name,
1419 ecs_entity_t type,
1420 ecs_size_t size,
1421 void *out);
1422
1423/** Return pointer to the value of a mut variable.
1424 * This operation returns the value of a mut variable, casted to the specified
1425 * type. If the type is equal to that of the mut variable, no cast is
1426 * performed. If the variable cannot be casted to the specified type, the
1427 * operation will throw an error.
1428 *
1429 * The returned value is owned by the caller. If the returned value contains
1430 * allocated memory, this needs to be freed by the caller.
1431 *
1432 * When the operation fails, a zero initialized value is returned.
1433 *
1434 * @param world The world.
1435 * @param name The name of the mut variable.
1436 * @param T The requested type.
1437 * @return The value of the mut variable.
1438 */
1439#define ecs_mut_var_get_t(world, name, T)\
1440 (*ECS_CAST(T*, ecs_mut_var_get_w_type(\
1441 world, name, ecs_id(T), ECS_SIZEOF(T), &(T){0})))
1442
1443/** Set the value of a mut variable.
1444 * This operation sets the value of a mut variable from a value of the
1445 * specified type. If the type is equal to that of the mut variable, no cast is
1446 * performed. If the value cannot be casted to the type of the mut variable,
1447 * the operation will throw an error.
1448 *
1449 * The provided value is copied into the storage of the mut variable and does
1450 * not need to be kept alive.
1451 *
1452 * On success, OnSet observers for the mut variable are notified, which causes
1453 * scripts that use the variable to be reevaluated.
1454 *
1455 * This operation is intended to be used by the ecs_mut_var_set_t macro.
1456 *
1457 * @param world The world.
1458 * @param name The name of the mut variable.
1459 * @param type The type of the provided value.
1460 * @param size The size of the provided type.
1461 * @param value Pointer to the value to set.
1462 * @return Zero if success, non-zero if failed.
1463 */
1464FLECS_API
1466 ecs_world_t *world,
1467 const char *name,
1468 ecs_entity_t type,
1469 ecs_size_t size,
1470 const void *value);
1471
1472/** Set the value of a mut variable.
1473 * This operation sets the value of a mut variable from a value of the
1474 * specified type. If the type is equal to that of the mut variable, no cast is
1475 * performed. If the value cannot be casted to the type of the mut variable,
1476 * the operation will throw an error.
1477 *
1478 * The provided value is copied into the storage of the mut variable and does
1479 * not need to be kept alive.
1480 *
1481 * On success, OnSet observers for the mut variable are notified, which causes
1482 * scripts that use the variable to be reevaluated.
1483 *
1484 * @param world The world.
1485 * @param name The name of the mut variable.
1486 * @param T The type of the provided value.
1487 * @return Zero if success, non-zero if failed.
1488 */
1489#define ecs_mut_var_set_t(world, name, T, ...)\
1490 ecs_mut_var_set_w_type(\
1491 world, name, ecs_id(T), ECS_SIZEOF(T), &(T)__VA_ARGS__)
1492
1493/** Mark mut var as modified.
1494 * This will notify OnSet observers.
1495 *
1496 * @param world The world.
1497 * @param var The mut variable.
1498 */
1499FLECS_API
1501 ecs_world_t *world,
1502 ecs_entity_t var);
1503
1504/* Functions */
1505
1506/** Vector function callbacks for different element types. */
1508 ecs_vector_function_callback_t i8; /**< Callback for i8 element type. */
1509 ecs_vector_function_callback_t i32; /**< Callback for i32 element type. */
1511
1512/** Used with ecs_function_init() and ecs_method_init(). */
1513typedef struct ecs_function_desc_t {
1514 /** Function name. */
1515 const char *name;
1516
1517 /** Parent of function. For methods the parent is the type for which the
1518 * method will be registered. */
1520
1521 /** Function parameters. */
1522 ecs_script_parameter_t params[FLECS_SCRIPT_FUNCTION_ARGS_MAX];
1523
1524 /** Function return type. Set to 0 for functions that do not return a
1525 * value. Functions without a return value cannot be used in expressions. */
1527
1528 /** Function implementation. */
1530
1531 /** Vector function implementations.
1532 * Set these callbacks if a function has one or more arguments of type
1533 * flecs.script.vector, and optionally a return type of flecs.script.vector.
1534 *
1535 * The flecs.script.vector type allows a function to be called with types
1536 * that meet the following constraints:
1537 * - The same type is provided for all arguments of type flecs.script.vector
1538 * - The provided type has one or more members of the same type
1539 * - The member type must be a primitive type
1540 * - The vector_callbacks array has an implementation for the primitive type.
1541 *
1542 * This allows for statements like:
1543 * @code
1544 * const a: Rgb = {100, 150, 250}
1545 * const b: Rgb = {10, 10, 10}
1546 * const r = lerp(a, b, 0.1)
1547 * @endcode
1548 *
1549 * which would otherwise have to be written out as:
1550 *
1551 * @code
1552 * const r: Rgb = {
1553 * lerp(a.r, b.r, 0.1),
1554 * lerp(a.g, b.g, 0.1),
1555 * lerp(a.b, b.b, 0.1)
1556 * }
1557 * @endcode
1558 *
1559 * To register vector functions, do:
1560 *
1561 * @code
1562 * ecs_function(world, {
1563 * .name = "lerp",
1564 * .return_type = EcsScriptVectorType,
1565 * .params = {
1566 * { .name = "a", .type = EcsScriptVectorType },
1567 * { .name = "b", .type = EcsScriptVectorType },
1568 * { .name = "t", .type = ecs_id(ecs_f64_t) }
1569 * },
1570 * .vector_callbacks = {
1571 * [EcsF32] = flecs_lerp32,
1572 * [EcsF64] = flecs_lerp64
1573 * }
1574 * });
1575 * @endcode
1576 *
1577 */
1578 ecs_vector_function_callback_t vector_callbacks[FLECS_SCRIPT_VECTOR_FUNCTION_COUNT];
1579
1580 /** Context passed to function implementation. */
1581 void *ctx;
1583
1584/** Create new function.
1585 * This operation creates a new function that can be called from a script.
1586 *
1587 * @param world The world.
1588 * @param desc Function init parameters.
1589 * @return The function, or 0 if failed.
1590*/
1591FLECS_API
1593 ecs_world_t *world,
1594 const ecs_function_desc_t *desc);
1595
1596#define ecs_function(world, ...)\
1597 ecs_function_init(world, &(ecs_function_desc_t)__VA_ARGS__)
1598
1599FLECS_API
1600int ecs_function_call(
1601 ecs_world_t *world,
1602 ecs_entity_t function,
1603 int32_t argc,
1604 const ecs_value_t *argv,
1605 ecs_value_t *result);
1606
1607/** Create new method.
1608 * This operation creates a new method that can be called from a script. A
1609 * method is like a function, except that it can be called on every instance of
1610 * a type.
1611 *
1612 * Methods automatically receive the instance on which the method is invoked as
1613 * first argument.
1614 *
1615 * @param world The world.
1616 * @param desc Method init parameters.
1617 * @return The method, or 0 if failed.
1618*/
1619FLECS_API
1621 ecs_world_t *world,
1622 const ecs_function_desc_t *desc);
1623
1624#define ecs_method(world, ...)\
1625 ecs_method_init(world, &(ecs_function_desc_t)__VA_ARGS__)
1626
1627FLECS_API
1628int ecs_method_call(
1629 ecs_world_t *world,
1630 ecs_entity_t method,
1631 const ecs_value_t *instance,
1632 int32_t argc,
1633 const ecs_value_t *argv,
1634 ecs_value_t *result);
1635
1636
1637/* Value serialization */
1638
1639/** Serialize value into expression string.
1640 * This operation serializes a value of the provided type to a string. The
1641 * memory pointed to must be large enough to contain a value of the used type.
1642 *
1643 * @param world The world.
1644 * @param type The type of the value to serialize.
1645 * @param data The value to serialize.
1646 * @return String with expression, or NULL if failed.
1647 */
1648FLECS_API
1650 const ecs_world_t *world,
1651 ecs_entity_t type,
1652 const void *data);
1653
1654/** Serialize value into expression buffer.
1655 * Same as ecs_ptr_to_expr(), but serializes to an ecs_strbuf_t instance.
1656 *
1657 * @param world The world.
1658 * @param type The type of the value to serialize.
1659 * @param data The value to serialize.
1660 * @param buf The strbuf to append the string to.
1661 * @return Zero if success, non-zero if failed.
1662 */
1663FLECS_API
1665 const ecs_world_t *world,
1666 ecs_entity_t type,
1667 const void *data,
1668 ecs_strbuf_t *buf);
1669
1670/** Similar to ecs_ptr_to_expr(), but serializes values to string.
1671 * Whereas the output of ecs_ptr_to_expr() is a valid expression, the output of
1672 * ecs_ptr_to_str() is a string representation of the value. In most cases the
1673 * output of the two operations is the same, but there are some differences:
1674 * - Strings are not quoted
1675 *
1676 * @param world The world.
1677 * @param type The type of the value to serialize.
1678 * @param data The value to serialize.
1679 * @return String with result, or NULL if failed.
1680 */
1681FLECS_API
1683 const ecs_world_t *world,
1684 ecs_entity_t type,
1685 const void *data);
1686
1687/** Serialize value into string buffer.
1688 * Same as ecs_ptr_to_str(), but serializes to an ecs_strbuf_t instance.
1689 *
1690 * @param world The world.
1691 * @param type The type of the value to serialize.
1692 * @param data The value to serialize.
1693 * @param buf The strbuf to append the string to.
1694 * @return Zero if success, non-zero if failed.
1695 */
1696FLECS_API
1698 const ecs_world_t *world,
1699 ecs_entity_t type,
1700 const void *data,
1701 ecs_strbuf_t *buf);
1702
1703/** Serialize a type to script.
1704 * This operation returns script code that declares the type with the struct,
1705 * enum, bitmask, vector, array or map declaration syntax. User-defined types
1706 * that the type depends on (types that are not stored in the flecs scope) are
1707 * declared first. Types that are stored in the scope of another entity are
1708 * declared in an entity scope for each parent. Running the returned code in a
1709 * world without the types recreates them.
1710 *
1711 * Primitive and opaque types cannot be declared by a script. The operation
1712 * fails when the type, or a user-defined type it depends on, is of such a kind.
1713 *
1714 * @param world The world.
1715 * @param type The type to serialize.
1716 * @return The script code, or NULL if failed. Must be freed with ecs_os_free().
1717 */
1718FLECS_API
1720 const ecs_world_t *world,
1721 ecs_entity_t type);
1722
1723typedef struct ecs_expr_node_t ecs_expr_node_t;
1724
1725/** Script module import function.
1726 * Usage:
1727 * @code
1728 * ECS_IMPORT(world, FlecsScript)
1729 * @endcode
1730 *
1731 * @param world The world.
1732 */
1733FLECS_API
1735 ecs_world_t *world);
1736
1737#ifdef __cplusplus
1738}
1739#endif
1740
1741#endif
1742
1743/** @} */
1744
1745#endif
FLECS_API int ecs_script_save(ecs_world_t *world, ecs_entity_t script)
Save the code of a managed script to the file it was loaded from.
FLECS_API int ecs_script_reload(ecs_world_t *world, ecs_entity_t script, const char *code)
Reload script from new code or from the file it was loaded from.
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.
Definition script.h:587
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.
Definition script.h:279
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 char * ecs_type_to_script(const ecs_world_t *world, ecs_entity_t type)
Serialize a type to script.
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.
Definition script.h:272
FLECS_API int ecs_script_undo(ecs_world_t *world, ecs_entity_t script)
Undo the last change to the code of a managed script.
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.
Definition script.h:165
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.
Definition script.h:125
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 int ecs_script_from_scene(ecs_world_t *world, ecs_entity_t script)
Update the code of a managed script with the current values of its entities.
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.
Definition script.h:172
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.
Definition flecs.h:396
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:440
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:389
script_builder script(const char *name=nullptr) const
Build a script.
Definition mixin.inl:31
#define ECS_DECLARE(id)
Forward declare an entity, tag, prefab, or any other entity identifier.
Definition flecs_c.h:25
#define ECS_COMPONENT_DECLARE(id)
Forward declare a component.
Definition flecs_c.h:65
void(*) ecs_ctx_free_t(void *ctx)
Function to clean up context data.
Definition flecs.h:661
Async/await support for Flecs script.
Const component.
Definition script.h:240
Mut component.
Definition script.h:250
Script component.
Definition script.h:130
ecs_vec_t observers
Observers for referenced components.
Definition script.h:136
ecs_vec_t dyn_observers
Observers for refs resolved at runtime.
Definition script.h:137
ecs_script_template_t * template_
Only set for template scripts.
Definition script.h:135
char * error
Set if script evaluation had errors.
Definition script.h:133
char * code
Script source code.
Definition script.h:132
bool ir
Evaluate script with IR runtime.
Definition script.h:139
ecs_script_t * script
Parsed script object.
Definition script.h:134
char * saved_code
Code as it was last loaded or saved.
Definition script.h:144
char * filename
Script filename.
Definition script.h:131
ecs_vec_t undo
Previous versions of the code, most recent last (vec<char*>).
Definition script.h:148
bool skip_unknown
Skip unknown components when loading.
Definition script.h:138
Used with ecs_const_var_init().
Definition script.h:1258
ecs_entity_t parent
Variable parent (namespace).
Definition script.h:1263
const char * name
Variable name.
Definition script.h:1260
ecs_entity_t type
Variable type.
Definition script.h:1266
void * value
Pointer to value of variable.
Definition script.h:1270
Used with ecs_expr_run().
Definition script.h:1145
bool disable_folding
Disable constant folding (slower evaluation, faster parsing).
Definition script.h:1157
void * script_visitor
For internal usage.
Definition script.h:1176
ecs_entity_t type
Type of parsed value (optional).
Definition script.h:1149
const ecs_script_vars_t * vars
Variables accessible in expression.
Definition script.h:1148
bool partial
When the expression is an initializer, only assign the members that the initializer sets.
Definition script.h:1172
ecs_script_runtime_t * runtime
Reusable runtime (optional).
Definition script.h:1174
bool allow_unresolved_identifiers
Allow for unresolved identifiers when parsing.
Definition script.h:1166
const char * name
Script name.
Definition script.h:1146
const char * expr
Full expression string.
Definition script.h:1147
bool disable_dynamic_variable_binding
This option instructs the expression runtime to lookup variables by stack pointer instead of by name,...
Definition script.h:1162
void * lookup_ctx
Context passed to lookup function.
Definition script.h:1154
Script function context.
Definition script.h:157
void * ctx
User context.
Definition script.h:161
ecs_entity_t function
The function entity.
Definition script.h:159
ecs_world_t * world
The world.
Definition script.h:158
ecs_entity_t entity
"this" entity (for methods and async functions).
Definition script.h:160
Used with ecs_function_init() and ecs_method_init().
Definition script.h:1513
ecs_entity_t return_type
Function return type.
Definition script.h:1526
const char * name
Function name.
Definition script.h:1515
ecs_script_parameter_t params[(16)]
Function parameters.
Definition script.h:1522
void * ctx
Context passed to function implementation.
Definition script.h:1581
ecs_function_callback_t callback
Function implementation.
Definition script.h:1529
ecs_vector_function_callback_t vector_callbacks[(18)]
Vector function implementations.
Definition script.h:1578
ecs_entity_t parent
Parent of function.
Definition script.h:1519
Iterator.
Definition flecs.h:1184
Used with ecs_mut_var_init().
Definition script.h:1351
void * value
Pointer to value of variable.
Definition script.h:1363
ecs_entity_t type
Variable type.
Definition script.h:1359
const char * name
Variable name.
Definition script.h:1353
ecs_entity_t parent
Variable parent (namespace).
Definition script.h:1356
Used with ecs_script_init().
Definition script.h:812
const char * code
Set to parse script from string.
Definition script.h:815
ecs_entity_t entity
Set to customize entity handle associated with script.
Definition script.h:813
bool skip_unknown
Skip unknown identifiers (see ecs_script_eval_desc_t::skip_unknown).
Definition script.h:816
bool ir
Evaluate script with IR runtime.
Definition script.h:817
const char * filename
Set to load script from file.
Definition script.h:814
Used with ecs_script_parse() and ecs_script_eval().
Definition script.h:193
bool ir
Evaluate script with the IR runtime instead of the AST interpreter.
Definition script.h:222
ecs_script_runtime_t * runtime
Reusable runtime (optional).
Definition script.h:194
bool skip_unknown
Skip unknown identifiers.
Definition script.h:219
Used to capture error output from script evaluation.
Definition script.h:226
char * error
Error message, or NULL if no error.
Definition script.h:227
int32_t line
Line number (1-based) of first error, or 0 if not available.
Definition script.h:228
int32_t column
Column number (1-based) of first error, or 0 if not available.
Definition script.h:229
Function argument type.
Definition script.h:180
const char * name
Parameter name.
Definition script.h:181
bool optional
Parameter may be omitted by the caller.
Definition script.h:187
ecs_entity_t type
Parameter type.
Definition script.h:182
const char * brief
Short description of the parameter (optional).
Definition script.h:189
Source location of a script statement.
Definition script.h:491
int32_t line
Line of the first character (1 based).
Definition script.h:494
int32_t offset
Offset of the first character of the statement.
Definition script.h:492
bool has_scope
Whether the statement is followed by a { } scope.
Definition script.h:496
ecs_entity_t template_
Set when the statement is inside the body of a template statement.
Definition script.h:502
int32_t length
Number of bytes occupied by the statement.
Definition script.h:493
int32_t column
Column of the first character (1 based).
Definition script.h:495
Script object.
Definition script.h:118
const char * code
Script source code.
Definition script.h:121
const char * name
Script name.
Definition script.h:120
ecs_world_t * world
The world.
Definition script.h:119
Script variable.
Definition script.h:94
bool is_const
Whether the variable is constant.
Definition script.h:99
ecs_value_t value
Variable value.
Definition script.h:96
bool owned
Whether the scope owns the value storage.
Definition script.h:100
const char * name
Variable name.
Definition script.h:95
const ecs_type_info_t * type_info
Type information.
Definition script.h:97
int32_t sp
Stack pointer.
Definition script.h:98
Script variable scope.
Definition script.h:104
int32_t sp
Stack pointer for this scope.
Definition script.h:106
ecs_allocator_t * allocator
General purpose allocator.
Definition script.h:114
struct ecs_script_vars_t * parent
Parent variable scope.
Definition script.h:105
struct ecs_stack_t * stack
Stack allocator for variable storage.
Definition script.h:112
ecs_stack_cursor_t * cursor
Cursor into the stack allocator.
Definition script.h:113
ecs_hashmap_t var_index
Index for variable name lookups.
Definition script.h:108
const ecs_world_t * world
The world.
Definition script.h:111
ecs_vec_t vars
Vector of variables in this scope.
Definition script.h:109
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1053
Value of a dynamic type.
Definition flecs.h:1069
Vector function callbacks for different element types.
Definition script.h:1507
ecs_vector_function_callback_t i8
Callback for i8 element type.
Definition script.h:1508
ecs_vector_function_callback_t i32
Callback for i32 element type.
Definition script.h:1509