Lua API: Add __dir metamethod to wesnoth.interface.game_display

This commit is contained in:
Celtic Minstrel 2024-09-10 23:16:54 -04:00 committed by Celtic Minstrel
parent c32ae8146e
commit fcd66c25a3
3 changed files with 13 additions and 0 deletions

View File

@ -1797,6 +1797,7 @@ REPORT_GENERATOR(report_countdown, rc)
void reports::register_generator(const std::string &name, reports::generator *g)
{
dynamic_generators_[name].reset(g);
all_reports_.clear();
}
config reports::generate_report(const std::string &name, const reports::context& rc, bool only_static)

View File

@ -4754,6 +4754,15 @@ int game_lua_kernel::impl_theme_items_set(lua_State *L)
return 0;
}
/**
* Get all available theme_items (__dir metamethod).
*/
int game_lua_kernel::impl_theme_items_dir(lua_State *L)
{
lua_push(L, reports_.report_list());
return 1;
}
/**
* Gets all the WML variables currently set.
* - Ret 1: WML table
@ -5381,6 +5390,8 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_set>);
lua_setfield(L, -2, "__newindex");
lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_theme_items_dir>);
lua_setfield(L, -2, "__dir");
lua_setmetatable(L, -2);
lua_setfield(L, -2, "game_display");
lua_pop(L, 1);

View File

@ -175,6 +175,7 @@ class game_lua_kernel : public lua_kernel_base
int impl_theme_item(lua_State *L, std::string name);
int impl_theme_items_get(lua_State *L);
int impl_theme_items_set(lua_State *L);
int impl_theme_items_dir(lua_State *L);
int cfun_builtin_effect(lua_State *L);
int cfun_wml_action(lua_State *L);
int intf_fire_event(lua_State *L, const bool by_id);