Skip to content

Commit

Permalink
Don't allow for adding anonymous entities in script
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Jul 7, 2024
1 parent fce692b commit 59e4c4b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
12 changes: 12 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -59424,8 +59424,20 @@ int flecs_script_eval_id(
return -1;
}

if (first == EcsAny || second == EcsAny) {
flecs_script_eval_error(v, node,
"cannot use anonymous entity as element of pair");
return -1;
}

id->eval = id->flag | ecs_pair(first, second);
} else {
if (first == EcsAny) {
flecs_script_eval_error(v, node,
"cannot use anonymous entity as component or tag");
return -1;
}

id->eval = id->flag | first;
}

Expand Down
12 changes: 12 additions & 0 deletions src/addons/script/visit_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,20 @@ int flecs_script_eval_id(
return -1;
}

if (first == EcsAny || second == EcsAny) {
flecs_script_eval_error(v, node,
"cannot use anonymous entity as element of pair");
return -1;
}

id->eval = id->flag | ecs_pair(first, second);
} else {
if (first == EcsAny) {
flecs_script_eval_error(v, node,
"cannot use anonymous entity as component or tag");
return -1;
}

id->eval = id->flag | first;
}

Expand Down
3 changes: 2 additions & 1 deletion test/script/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@
"pair_second_not_found",
"kind_not_found",
"base_not_found",
"dont_inherit_script_pair"
"dont_inherit_script_pair",
"entity_w_anon_tag"
]
}, {
"id": "Template",
Expand Down
18 changes: 18 additions & 0 deletions test/script/src/Eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -8254,3 +8254,21 @@ void Eval_dont_inherit_script_pair(void) {

ecs_fini(world);
}

void Eval_entity_w_anon_tag(void) {
ecs_world_t *world = ecs_init();

const char *expr =
LINE "MyEntity {"
LINE " _"
LINE "}";

ecs_log_set_level(-4);
ecs_entity_t s = ecs_script(world, {
.entity = ecs_entity(world, { .name = "main" }),
.code = expr
});
test_assert(s == 0);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/script/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ void Eval_pair_second_not_found(void);
void Eval_kind_not_found(void);
void Eval_base_not_found(void);
void Eval_dont_inherit_script_pair(void);
void Eval_entity_w_anon_tag(void);

// Testsuite 'Template'
void Template_template_no_scope(void);
Expand Down Expand Up @@ -1695,6 +1696,10 @@ bake_test_case Eval_testcases[] = {
{
"dont_inherit_script_pair",
Eval_dont_inherit_script_pair
},
{
"entity_w_anon_tag",
Eval_entity_w_anon_tag
}
};

Expand Down Expand Up @@ -2979,7 +2984,7 @@ static bake_test_suite suites[] = {
"Eval",
NULL,
NULL,
272,
273,
Eval_testcases
},
{
Expand Down

0 comments on commit 59e4c4b

Please sign in to comment.