Lua API: Add __dir metamethod to wesnoth.terrain_types
This commit is contained in:
parent
cb1853b4bc
commit
711b77b7e2
2 changed files with 19 additions and 0 deletions
|
@ -1124,6 +1124,22 @@ int game_lua_kernel::impl_get_terrain_info(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of known terrain codes.
|
||||
* - Ret 1: array of terrain codes
|
||||
*/
|
||||
int game_lua_kernel::impl_get_terrain_list(lua_State *L)
|
||||
{
|
||||
auto codes = board().map().tdata()->list();
|
||||
std::vector<std::string> terrains;
|
||||
terrains.reserve(codes.size());
|
||||
for(auto code : codes) {
|
||||
terrains.push_back(t_translation::write_terrain_code(code));
|
||||
}
|
||||
lua_push(L, terrains);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets time of day information.
|
||||
* - Arg 1: schedule object, location, time area ID, or nil
|
||||
|
@ -5267,6 +5283,8 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
|
|||
lua_createtable(L, 0, 2);
|
||||
lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_info>);
|
||||
lua_setfield(L, -2, "__index");
|
||||
lua_pushcfunction(L, &dispatch<&game_lua_kernel::impl_get_terrain_list>);
|
||||
lua_setfield(L, -2, "__dir");
|
||||
lua_pushstring(L, "terrain types");
|
||||
lua_setfield(L, -2, "__metatable");
|
||||
lua_setmetatable(L, -2);
|
||||
|
|
|
@ -97,6 +97,7 @@ class game_lua_kernel : public lua_kernel_base
|
|||
int intf_view_locked(lua_State *L);
|
||||
int intf_lock_view(lua_State *L);
|
||||
int impl_get_terrain_info(lua_State *L);
|
||||
int impl_get_terrain_list(lua_State *L);
|
||||
template<bool consider_illuminates>
|
||||
int intf_get_time_of_day(lua_State *L);
|
||||
int impl_schedule_get(lua_State *L);
|
||||
|
|
Loading…
Add table
Reference in a new issue