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