Skip to content
Flecs v4.1
script/expr_run

  • C

    View on GitHub

    1#include <expr_run.h>
    2#include <stdio.h>
    3
    4// This example shows how to run an expression once. To see how to parse an
    5// expression and run it multiple times, see the expr_w_vars example.
    6
    7int main(int argc, char *argv[]) {
    8 ecs_world_t *world = ecs_init_w_args(argc, argv);
    9
    10 // Declare value that will hold the expression result. Specify that we want
    11 // the returned value to be of type i32. If the expression type doesn't
    12 // match the specified type, it will be casted.
    13 int32_t result = 0;
    14 ecs_value_t result_value = {
    15 .type = ecs_id(ecs_i32_t),
    16 .ptr = &result
    17 };
    18
    19 // Run the expression. If the operation is successful it returns a pointer
    20 // to the character after the last parsed token.
    21 if (ecs_expr_run(world, "10 + 20", &result_value, NULL) == NULL) {
    22 printf("expression failed to run\n");
    23 return -1;
    24 }
    25
    26 printf("result = %d\n", result);
    27
    28 return ecs_fini(world);
    29
    30 // Output
    31 // result = 30
    32}
    FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
    Component ID for EcsDocDescription.
    int32_t ecs_i32_t
    Built-in i32 type.
    Definition meta.h:105
    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.
    struct ecs_world_t ecs_world_t
    A world is the container for all ECS data and supporting features.
    Definition flecs.h:439
    int ecs_fini(ecs_world_t *world)
    Delete a world.
    ecs_world_t * ecs_init_w_args(int argc, char *argv[])
    Create a new world with arguments.
    Value of a dynamic type.
    Definition flecs.h:1068