Skip to content

Commit

Permalink
Add missing ecs_rule_var_count function
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 7, 2023
1 parent 80b88a7 commit 83d7468
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38626,6 +38626,12 @@ int32_t ecs_rule_find_var(
return (int32_t)var_id;
}

int32_t ecs_rule_var_count(
const ecs_rule_t *rule)
{
return rule->var_pub_count;
}

static
const char* flecs_term_id_var_name(
ecs_term_id_t *term_id)
Expand Down
6 changes: 6 additions & 0 deletions src/addons/rules/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ int32_t ecs_rule_find_var(
return (int32_t)var_id;
}

int32_t ecs_rule_var_count(
const ecs_rule_t *rule)
{
return rule->var_pub_count;
}

static
const char* flecs_term_id_var_name(
ecs_term_id_t *term_id)
Expand Down
3 changes: 2 additions & 1 deletion test/addons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@
"parse_2_vars_w_spaces",
"parse_0_var_paren_w_spaces",
"parse_1_var_paren_w_spaces",
"parse_2_vars_paren_w_spaces"
"parse_2_vars_paren_w_spaces",
"var_count"
]
}, {
"id": "RulesOperators",
Expand Down
13 changes: 13 additions & 0 deletions test/addons/src/RulesVariables.c
Original file line number Diff line number Diff line change
Expand Up @@ -5785,3 +5785,16 @@ void RulesVariables_parse_2_vars_paren_w_spaces() {

ecs_fini(world);
}

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

ecs_rule_t *r = ecs_rule(world, {
.expr = "$x($this, $y), $x($this), $y($this)"
});
test_assert(r != NULL);

test_int(ecs_rule_var_count(r), 3);

ecs_fini(world);
}
7 changes: 6 additions & 1 deletion test/addons/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ void RulesVariables_parse_2_vars_w_spaces(void);
void RulesVariables_parse_0_var_paren_w_spaces(void);
void RulesVariables_parse_1_var_paren_w_spaces(void);
void RulesVariables_parse_2_vars_paren_w_spaces(void);
void RulesVariables_var_count(void);

// Testsuite 'RulesOperators'
void RulesOperators_2_and_not(void);
Expand Down Expand Up @@ -4375,6 +4376,10 @@ bake_test_case RulesVariables_testcases[] = {
{
"parse_2_vars_paren_w_spaces",
RulesVariables_parse_2_vars_paren_w_spaces
},
{
"var_count",
RulesVariables_var_count
}
};

Expand Down Expand Up @@ -6641,7 +6646,7 @@ static bake_test_suite suites[] = {
"RulesVariables",
NULL,
NULL,
90,
91,
RulesVariables_testcases
},
{
Expand Down

0 comments on commit 83d7468

Please sign in to comment.