mirror of https://github.com/OpenMW/openmw
Don't accept table like objects in getFieldOrNil
This commit is contained in:
parent
cd4901245e
commit
fdbcada044
|
|
@ -258,7 +258,7 @@ return {
|
|||
TEST_F(LuaStateTest, SafeIndexMetamethod)
|
||||
{
|
||||
const VFS::Path::Normalized path("metaIndexError.lua");
|
||||
sol::table t = mLua.runInNewSandbox(path);
|
||||
sol::lua_table t = mLua.runInNewSandbox(path);
|
||||
// without safe get we crash here
|
||||
EXPECT_ERROR(LuaUtil::safeGet(t, "any key"), "meta index error");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ namespace LuaUtil
|
|||
// work around for a (likely) sol3 bug
|
||||
// when the index meta method throws, simply calling table.get crashes instead of re-throwing the error
|
||||
template <class Key>
|
||||
sol::object safeGet(const sol::table& table, const Key& key)
|
||||
sol::object safeGet(const sol::lua_table& table, const Key& key)
|
||||
{
|
||||
auto index = table.traverse_raw_get<sol::optional<sol::main_protected_function>>(
|
||||
sol::metatable_key, sol::meta_function::index);
|
||||
|
|
@ -306,9 +306,9 @@ namespace LuaUtil
|
|||
template <class... Str>
|
||||
sol::object getFieldOrNil(const sol::object& table, std::string_view first, const Str&... str)
|
||||
{
|
||||
if (!table.is<sol::table>())
|
||||
if (!table.is<sol::lua_table>())
|
||||
return sol::nil;
|
||||
sol::object value = safeGet(table.as<sol::table>(), first);
|
||||
sol::object value = safeGet(table.as<sol::lua_table>(), first);
|
||||
if constexpr (sizeof...(str) == 0)
|
||||
return value;
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue