diff --git a/src/scripting/lua_common.cpp b/src/scripting/lua_common.cpp index ed591803fbbc..0dee32b32bfe 100644 --- a/src/scripting/lua_common.cpp +++ b/src/scripting/lua_common.cpp @@ -745,8 +745,9 @@ bool luaW_toconfig(lua_State *L, int index, config &cfg) // Then convert the attributes (string indices). for (lua_pushnil(L); lua_next(L, index); lua_pop(L, 1)) { - if (lua_isnumber(L, -2)) continue; - if (!lua_isstring(L, -2)) return_misformed(); + int indextype = lua_type(L, -2); + if (indextype == LUA_TNUMBER) continue; + if (indextype != LUA_TSTRING) return_misformed(); config::attribute_value &v = cfg[lua_tostring(L, -2)]; if (lua_istable(L, -1)) { int subindex = lua_absindex(L, -1); @@ -760,7 +761,7 @@ bool luaW_toconfig(lua_State *L, int index, config &cfg) } // If there are any string keys, it's misformed for (lua_pushnil(L); lua_next(L, subindex); lua_pop(L, 1)) { - if (!lua_isnumber(L, -2)) return_misformed(); + if (lua_type(L, -2) != LUA_TNUMBER) return_misformed(); } v = str.str(); } else if (!luaW_toscalar(L, -1, v)) return_misformed(); diff --git a/src/scripting/lua_formula_bridge.cpp b/src/scripting/lua_formula_bridge.cpp index 8607d3b98ac3..0e4b29728d4c 100644 --- a/src/scripting/lua_formula_bridge.cpp +++ b/src/scripting/lua_formula_bridge.cpp @@ -70,7 +70,10 @@ class lua_callable : public formula_callable { add_input(inputs, "__list"); add_input(inputs, "__map"); for(lua_pushnil(mState); lua_next(mState, table_i); lua_pop(mState,1)) { - if(lua_isstring(mState, -2) && !lua_isnumber(mState, -2)) { + lua_pushvalue(mState, -2); + bool is_valid_key = (lua_type(mState, -1) == LUA_TSTRING) && !lua_isnumber(mState, -1); + lua_pop(mState, 1); + if(is_valid_key) { std::string key = lua_tostring(mState, -2); if(key.find_first_not_of(formula::id_chars) != std::string::npos) { add_input(inputs, key); diff --git a/src/scripting/lua_kernel_base.cpp b/src/scripting/lua_kernel_base.cpp index 08507dcc9fd2..d4dd6e0b37c1 100644 --- a/src/scripting/lua_kernel_base.cpp +++ b/src/scripting/lua_kernel_base.cpp @@ -178,7 +178,7 @@ static int intf_name_generator(lua_State *L) if(lua_istable(L, 2)) { std::map> data; for(lua_pushnil(L); lua_next(L, 2); lua_pop(L, 1)) { - if(!lua_isstring(L, -2)) { + if(lua_type(L, -2) != LUA_TSTRING) { lua_pushstring(L, "CFG generator: invalid nonterminal name (must be a string)"); return lua_error(L); } @@ -914,7 +914,7 @@ std::vector lua_kernel_base::get_attribute_names(const std::string lua_settop(L, top); // Metafunction not found, so use lua_next to enumerate the table for(lua_pushnil(L); lua_next(L, obj); lua_pop(L, 1)) { - if(lua_isstring(L, -2)) { + if(lua_type(L, -2) == LUA_TSTRING) { std::string attr = lua_tostring(L, -2); if(attr.empty()) { continue;