mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Add function to get all HUD elements (#14042)
This commit is contained in:
parent
ed7d4037b2
commit
92c55c27cf
9 changed files with 85 additions and 0 deletions
|
@ -422,6 +422,26 @@ int LuaLocalPlayer::l_hud_get(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// hud_get_all(self)
|
||||
int LuaLocalPlayer::l_hud_get_all(lua_State *L)
|
||||
{
|
||||
LocalPlayer *player = getobject(L, 1);
|
||||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
lua_newtable(L);
|
||||
player->hudApply([&](const std::vector<HudElement*>& hud) {
|
||||
for (std::size_t id = 0; id < hud.size(); ++id) {
|
||||
HudElement *elem = hud[id];
|
||||
if (elem != nullptr) {
|
||||
push_hud_element(L, elem);
|
||||
lua_rawseti(L, -2, id);
|
||||
}
|
||||
}
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
||||
LocalPlayer *LuaLocalPlayer::getobject(LuaLocalPlayer *ref)
|
||||
{
|
||||
return ref->m_localplayer;
|
||||
|
@ -483,6 +503,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
|
|||
luamethod(LuaLocalPlayer, hud_remove),
|
||||
luamethod(LuaLocalPlayer, hud_change),
|
||||
luamethod(LuaLocalPlayer, hud_get),
|
||||
luamethod(LuaLocalPlayer, hud_get_all),
|
||||
|
||||
luamethod(LuaLocalPlayer, get_move_resistance),
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue