diff --git a/apps/openmw/mwlua/objectbindings.cpp b/apps/openmw/mwlua/objectbindings.cpp index 2a0aa87d15..ace9722bbe 100644 --- a/apps/openmw/mwlua/objectbindings.cpp +++ b/apps/openmw/mwlua/objectbindings.cpp @@ -330,10 +330,9 @@ namespace MWLua return LuaUtil::Box{ bb.center(), bb._max - bb.center() }; }; - objectT["type"] - = sol::readonly_property([types = getTypeToPackageTable(context.sol())](const ObjectT& o) mutable { - return types[getLiveCellRefType(o.ptr().mRef)]; - }); + objectT["type"] = sol::readonly_property( + [types = getTypeToPackageTable(context.sol())]( + const ObjectT& o) -> sol::object { return types[getLiveCellRefType(o.ptr().mRef)]; }); objectT["count"] = sol::readonly_property([](const ObjectT& o) { return o.ptr().getCellRef().getCount(); }); objectT[sol::meta_function::equal_to] = [](const ObjectT& a, const ObjectT& b) { return a.id() == b.id(); }; diff --git a/scripts/data/integration_tests/test_lua_api/global.lua b/scripts/data/integration_tests/test_lua_api/global.lua index fec0b4ead6..dbc1864195 100644 --- a/scripts/data/integration_tests/test_lua_api/global.lua +++ b/scripts/data/integration_tests/test_lua_api/global.lua @@ -7,6 +7,13 @@ local vfs = require('openmw.vfs') local world = require('openmw.world') local I = require('openmw.interfaces') +testing.registerGlobalTest('crash in lua coroutine when accessing type (#8757)', function() + local co = coroutine.wrap(function() + testing.expectEqual(tostring(world.players[1].type), 'Player') + end) + co() +end) + testing.registerGlobalTest('timers', function() testing.expectAlmostEqual(core.getGameTimeScale(), 30, 'incorrect getGameTimeScale() result') testing.expectAlmostEqual(core.getSimulationTimeScale(), 1, 'incorrect getSimulationTimeScale result') diff --git a/scripts/data/integration_tests/test_lua_api/menu.lua b/scripts/data/integration_tests/test_lua_api/menu.lua index ca5f40c526..52c2c15d00 100644 --- a/scripts/data/integration_tests/test_lua_api/menu.lua +++ b/scripts/data/integration_tests/test_lua_api/menu.lua @@ -61,6 +61,7 @@ local function registerGlobalTest(name, description) end) end +registerGlobalTest('crash in lua coroutine when accessing type (#8757)') registerGlobalTest('timers') registerGlobalTest('teleport') registerGlobalTest('getGMST')