1#include <functions.h>
2#include <stdio.h>
3
4
5
6const char *code =
7 "e {\n"
8 " Position: { sum(10, 20), (30).add(40) }\n"
9 "}\n"
10 ;
11
12typedef struct {
13 int32_t x, y;
14} Position;
15
16void sum(
18 int argc,
21{
22 (void)ctx;
23 (void)argc;
24
25 *(int64_t*)result->
ptr =
26 *(int64_t*)argv[0].
ptr +
27 *(int64_t*)argv[1].ptr;
28}
29
30int main(int argc, char *argv[]) {
32
34
35
37 .entity =
ecs_id(Position),
38 .members = {
41 }
42 });
43
44
45 ecs_function(world, {
46 .name = "sum",
48 .params = {
51 },
52 .callback = sum
53 });
54
55
56
57 ecs_method(world, {
58 .name = "add",
61 .params = {
63 },
64 .callback = sum
65 });
66
68 printf("script failed to run\n");
69 return -1;
70 }
71
72
74 const Position *p =
ecs_get(world, e, Position);
75
76 printf("{x: %d, y: %d}\n", p->x, p->y);
77
79
80
81
82}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
FLECS_API int ecs_script_run(ecs_world_t *world, const char *name, const char *code, ecs_script_eval_result_t *result)
Parse script.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
#define ECS_COMPONENT(world, id)
Declare and define a component.
#define ecs_get(world, entity, T)
Get a component.
ecs_entity_t ecs_lookup(const ecs_world_t *world, const char *path)
Look up an entity by its path.
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.
void * ptr
Pointer to value.