mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 00:25:19 +02:00
HUD: Reject and warn on invalid stat types (#11548)
This comes into play on older servers which do not know the "stat" type. Warnings are only logged once to avoid spam within globalstep callbacks
This commit is contained in:
@@ -1989,15 +1989,17 @@ void push_hud_element(lua_State *L, HudElement *elem)
|
||||
lua_setfield(L, -2, "style");
|
||||
}
|
||||
|
||||
HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
|
||||
bool read_hud_change(lua_State *L, HudElementStat &stat, HudElement *elem, void **value)
|
||||
{
|
||||
HudElementStat stat = HUD_STAT_NUMBER;
|
||||
std::string statstr;
|
||||
if (lua_isstring(L, 3)) {
|
||||
std::string statstr = lua_tostring(L, 3);
|
||||
{
|
||||
int statint;
|
||||
statstr = lua_tostring(L, 3);
|
||||
stat = string_to_enum(es_HudElementStat, statint, statstr) ?
|
||||
(HudElementStat)statint : stat;
|
||||
if (!string_to_enum(es_HudElementStat, statint, statstr)) {
|
||||
script_log_unique(L, "Unknown HUD stat type: " + statstr, warningstream);
|
||||
return false;
|
||||
}
|
||||
|
||||
stat = (HudElementStat)statint;
|
||||
}
|
||||
|
||||
switch (stat) {
|
||||
@@ -2060,7 +2062,8 @@ HudElementStat read_hud_change(lua_State *L, HudElement *elem, void **value)
|
||||
*value = &elem->style;
|
||||
break;
|
||||
}
|
||||
return stat;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
Reference in New Issue
Block a user