Skip to content

Commit

Permalink
Fix issue with using ECS_PRIVATE in meta struct definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 18, 2023
1 parent 5f8ccee commit a91566b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -44155,6 +44155,10 @@ const char* meta_parse_member(
goto error;
}

if (!ptr[0]) {
return ptr;
}

/* Next token is the identifier */
ptr = parse_c_identifier(ptr, token->name, NULL, ctx);
if (!ptr) {
Expand Down
4 changes: 4 additions & 0 deletions src/addons/meta_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ const char* meta_parse_member(
goto error;
}

if (!ptr[0]) {
return ptr;
}

/* Next token is the identifier */
ptr = parse_c_identifier(ptr, token->name, NULL, ctx);
if (!ptr) {
Expand Down
3 changes: 2 additions & 1 deletion test/meta/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@
"enum_nospace",
"struct_nospace",
"identifier_w_underscore",
"struct_w_ptr"
"struct_w_ptr",
"private_members"
]
}, {
"id": "Vars",
Expand Down
31 changes: 31 additions & 0 deletions test/meta/src/MetaUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ ECS_STRUCT(Struct_w_ptrs, {
void* ptr_b;
});

ECS_STRUCT(Struct_w_private, {
double x;
double y;
ECS_PRIVATE
double z;
});

ECS_ENUM(Enum_Default, {
Red, Green, Blue
});
Expand Down Expand Up @@ -388,3 +395,27 @@ void MetaUtils_struct_w_ptr() {

ecs_fini(world);
}

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

ECS_META_COMPONENT(world, Struct_w_private);

test_assert(ecs_id(Struct_w_private) != 0);
ecs_entity_t s = ecs_id(Struct_w_private);

{
ecs_entity_t m = ecs_lookup_child(world, s, "x");
test_assert(m != 0);
}
{
ecs_entity_t m = ecs_lookup_child(world, s, "y");
test_assert(m != 0);
}
{
ecs_entity_t m = ecs_lookup_child(world, s, "z");
test_assert(m == 0);
}

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/meta/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ void MetaUtils_enum_nospace(void);
void MetaUtils_struct_nospace(void);
void MetaUtils_identifier_w_underscore(void);
void MetaUtils_struct_w_ptr(void);
void MetaUtils_private_members(void);

// Testsuite 'Vars'
void Vars_declare_1_var(void);
Expand Down Expand Up @@ -3851,6 +3852,10 @@ bake_test_case MetaUtils_testcases[] = {
{
"struct_w_ptr",
MetaUtils_struct_w_ptr
},
{
"private_members",
MetaUtils_private_members
}
};

Expand Down Expand Up @@ -4473,7 +4478,7 @@ static bake_test_suite suites[] = {
"MetaUtils",
NULL,
NULL,
17,
18,
MetaUtils_testcases
},
{
Expand Down

0 comments on commit a91566b

Please sign in to comment.