Skip to content

Commit a8e36cf

Browse files
committed
Fixed configClasses returning non-class entities
1 parent 495f521 commit a8e36cf

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/operators/ops_config.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ namespace
252252
{
253253
if (res->is<t_boolean>())
254254
{
255-
if (res->data<d_boolean, bool>()) {
255+
auto nav = m_iterator_current.nav();
256+
bool is_class = nav->size() > 0 || (nav->size() == 0 && nav->value.empty());
257+
if (res->data<d_boolean, bool>() && is_class) {
256258
m_out_arr->push_back({ *m_iterator_current });
257259
}
258260
}
@@ -415,4 +417,4 @@ void sqf::operators::ops_config(::sqf::runtime::runtime& runtime)
415417
runtime.register_sqfop(unary("isNull", t_config(), "Checks whether the tested item is Null.", isnull_config));
416418
runtime.register_sqfop(binary(4, "configClasses", t_string(), t_config(), "Returns an array of t_config() entries which meet criteria in condition code. Command iterates through all available t_config() sub classes of the given t_config() class. Current looked at t_config() is stored in _x variable (similar to alternative count command implementation). Condition has to return true in order for the looked at t_config() to be added to the resulting array. Slightly faster than configProperties, but doesn't account for t_config() properties or inherited entries.", configclasses_code_config));
417419
runtime.register_sqfop(unary("configProperties", t_array(), "Returns an array of t_config() entries which meet criteria in condition code. Command iterates through available classes and t_config() properties for given t_config() entry. If 3rd param is true the search also includes inherited properties. Current looked at t_config() is stored in _x variable (similar to alternative count command implementation). Condition has to return true in order for the looked at property to be added to the resulting array. A bit slower than configClasses but allows to access inherited entires.", configproperties_array));
418-
}
420+
}

src/runtime/confighost.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ namespace sqf::runtime
181181
auto actual_index = container[m_index];
182182
return m_confighost.m_containers[actual_index];
183183
}
184+
inline confignav nav()
185+
{
186+
auto& container = m_confighost.m_containers[m_id];
187+
auto actual_index = container[m_index];
188+
return confignav(m_confighost, actual_index);
189+
}
184190
};
185191
using iterator = iterator_base<false>;
186192
using iterator_recursive = iterator_base<true>;
@@ -414,4 +420,4 @@ namespace sqf::runtime
414420
};
415421
inline confignav config::navigate(confighost& host) const { return { host, m_container_id }; }
416422
inline confignav confighost::root() { return { *this, 0 }; }
417-
}
423+
}

tests/sqf/config.sqf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,7 @@
5555
["assertEqual", { ("getNumber (_x >> 'key') == 5" configClasses (configFile >> "flat_tests")) }, [configFile >> "flat_tests" >> "E"]],
5656
["assertEqual", { ("(getNumber (_x >> 'key')) % 2 == 0" configClasses (configFile >> "flat_tests")) }, [configFile >> "flat_tests" >> "B", configFile >> "flat_tests" >> "D"]],
5757
["assertEqual", { configName ((configFile >> "test_select_selects_addon") select 0) }, "addon"],
58-
["assertEqual", { ("true" configClasses (configFile >> "test_config_classes_only_returns_config_entries")) apply { configName _x } }, ["TestSub"]]
58+
["assertEqual", { ("true" configClasses (configFile >> "test_config_classes_only_returns_config_entries")) apply { configName _x } }, ["TestSub"]],
59+
["assertEqual", { ("true" configClasses (configFile >> "nested_tests")) apply { configName _x } }, ["nested1"]],
60+
["assertEqual", { ("true" configClasses (configFile >> "nested_tests" >> "nested1")) apply { configName _x } }, ["nested2"]]
5961
]

0 commit comments

Comments
 (0)