[Lua] Fix an error reading filters in wesnoth.game_events.add

This commit is contained in:
Celtic Minstrel 2024-02-07 22:09:55 -05:00
parent a9c0d37525
commit 249f9e70f9

View file

@ -4057,25 +4057,25 @@ int game_lua_kernel::intf_add_event(lua_State *L)
new_handler->add_filter(std::make_unique<lua_event_filter>(*this, fcnIdx, luaW_table_get_def(L, 1, "filter_args", config()))); new_handler->add_filter(std::make_unique<lua_event_filter>(*this, fcnIdx, luaW_table_get_def(L, 1, "filter_args", config())));
has_lua_filter = true; has_lua_filter = true;
} else { } else {
#define READ_ONE_FILTER(key) \ #define READ_ONE_FILTER(key, tag) \
do { \ do { \
if(luaW_tableget(L, filterIdx, key)) { \ if(luaW_tableget(L, filterIdx, key)) { \
if(lua_isstring(L, -1)) { \ if(lua_isstring(L, -1)) { \
filters.add_child("insert_tag", config{ \ filters.add_child("insert_tag", config{ \
"name", "filter_" key, \ "name", tag, \
"variable", luaL_checkstring(L, -1) \ "variable", luaL_checkstring(L, -1) \
}); \ }); \
} else { \ } else { \
filters.add_child("filter_" key, luaW_checkconfig(L, -1)); \ filters.add_child(tag, luaW_checkconfig(L, -1)); \
} \ } \
} \ } \
} while(false); } while(false);
READ_ONE_FILTER("condition"); READ_ONE_FILTER("condition", "filter_condition");
READ_ONE_FILTER("side"); READ_ONE_FILTER("side", "filter_side");
READ_ONE_FILTER("unit"); READ_ONE_FILTER("unit", "filter");
READ_ONE_FILTER("attack"); READ_ONE_FILTER("attack", "filter_attack");
READ_ONE_FILTER("second_unit"); READ_ONE_FILTER("second_unit", "filter_second");
READ_ONE_FILTER("second_attack"); READ_ONE_FILTER("second_attack", "filter_second_attack");
#undef READ_ONE_FILTER #undef READ_ONE_FILTER
if(luaW_tableget(L, filterIdx, "formula")) { if(luaW_tableget(L, filterIdx, "formula")) {
filters["filter_formula"] = luaL_checkstring(L, -1); filters["filter_formula"] = luaL_checkstring(L, -1);