Skip to content

Commit fdbcada

Browse files
committed
Don't accept table like objects in getFieldOrNil
1 parent cd49012 commit fdbcada

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

apps/components_tests/lua/testlua.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ return {
258258
TEST_F(LuaStateTest, SafeIndexMetamethod)
259259
{
260260
const VFS::Path::Normalized path("metaIndexError.lua");
261-
sol::table t = mLua.runInNewSandbox(path);
261+
sol::lua_table t = mLua.runInNewSandbox(path);
262262
// without safe get we crash here
263263
EXPECT_ERROR(LuaUtil::safeGet(t, "any key"), "meta index error");
264264
}

components/lua/luastate.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ namespace LuaUtil
286286
// work around for a (likely) sol3 bug
287287
// when the index meta method throws, simply calling table.get crashes instead of re-throwing the error
288288
template <class Key>
289-
sol::object safeGet(const sol::table& table, const Key& key)
289+
sol::object safeGet(const sol::lua_table& table, const Key& key)
290290
{
291291
auto index = table.traverse_raw_get<sol::optional<sol::main_protected_function>>(
292292
sol::metatable_key, sol::meta_function::index);
@@ -306,9 +306,9 @@ namespace LuaUtil
306306
template <class... Str>
307307
sol::object getFieldOrNil(const sol::object& table, std::string_view first, const Str&... str)
308308
{
309-
if (!table.is<sol::table>())
309+
if (!table.is<sol::lua_table>())
310310
return sol::nil;
311-
sol::object value = safeGet(table.as<sol::table>(), first);
311+
sol::object value = safeGet(table.as<sol::lua_table>(), first);
312312
if constexpr (sizeof...(str) == 0)
313313
return value;
314314
else

0 commit comments

Comments
 (0)