From 823dc6a8969f05d59e40b2c9b623b2117370ab20 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 23 Oct 2025 20:51:01 +0200 Subject: [PATCH 1/2] Return type as a sol::object instead of a table proxy --- apps/openmw/mwlua/objectbindings.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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(); }; From d147006c641b247a2505a8084f62ae519835288d Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 25 Oct 2025 11:10:45 +0200 Subject: [PATCH 2/2] Add integration test --- scripts/data/integration_tests/test_lua_api/global.lua | 7 +++++++ scripts/data/integration_tests/test_lua_api/menu.lua | 1 + 2 files changed, 8 insertions(+) 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')