Re-fix hud_change stat argument retrieval
authorkwolekr <kwolekr@minetest.net>
Sun, 21 Apr 2013 16:55:46 +0000 (12:55 -0400)
committerKahrl <kahrl@gmx.net>
Thu, 26 Sep 2013 02:39:10 +0000 (04:39 +0200)
Conflicts:
src/script/lua_api/l_object.cpp

src/script/lua_api/l_object.cpp

index 6a800f15dedad5b4fac78026e66a3555c80fbc00..c324ced1a390b45875029cff1f19ec3ead265b34 100644 (file)
@@ -877,16 +877,18 @@ int ObjectRef::l_hud_change(lua_State *L)
        if (player == NULL)
                return 0;
 
-       u32 id = -1;
-       if (!lua_isnil(L, 2))
-               id = lua_tonumber(L, 2);
-
-       HudElementStat stat = (HudElementStat)getenumfield(L, 3, "stat",
-                                                               es_HudElementStat, HUD_STAT_NUMBER);
-
+       u32 id = !lua_isnil(L, 2) ? lua_tonumber(L, 2) : -1;
        if (id >= player->hud.size())
                return 0;
 
+       HudElementStat stat = HUD_STAT_NUMBER;
+       if (!lua_isnil(L, 3)) {
+               int statint;
+               std::string statstr = lua_tostring(L, 3);
+               stat = string_to_enum(es_HudElementStat, statint, statstr) ?
+                               (HudElementStat)statint : HUD_STAT_NUMBER;
+       }
+
        void *value = NULL;
        HudElement *e = player->hud[id];
        if (!e)