mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 05:26:39 +00:00 
			
		
		
		
	Merge branch 'objectifyyourtype' into 'master'
Return type as a sol::object instead of a table proxy Closes #8757 See merge request OpenMW/openmw!4963
This commit is contained in:
		
						commit
						23f843c552
					
				
					 3 changed files with 11 additions and 4 deletions
				
			
		| 
						 | 
					@ -330,10 +330,9 @@ namespace MWLua
 | 
				
			||||||
                return LuaUtil::Box{ bb.center(), bb._max - bb.center() };
 | 
					                return LuaUtil::Box{ bb.center(), bb._max - bb.center() };
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            objectT["type"]
 | 
					            objectT["type"] = sol::readonly_property(
 | 
				
			||||||
                = sol::readonly_property([types = getTypeToPackageTable(context.sol())](const ObjectT& o) mutable {
 | 
					                [types = getTypeToPackageTable(context.sol())](
 | 
				
			||||||
                      return types[getLiveCellRefType(o.ptr().mRef)];
 | 
					                    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["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(); };
 | 
					            objectT[sol::meta_function::equal_to] = [](const ObjectT& a, const ObjectT& b) { return a.id() == b.id(); };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,13 @@ local vfs = require('openmw.vfs')
 | 
				
			||||||
local world = require('openmw.world')
 | 
					local world = require('openmw.world')
 | 
				
			||||||
local I = require('openmw.interfaces')
 | 
					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.registerGlobalTest('timers', function()
 | 
				
			||||||
    testing.expectAlmostEqual(core.getGameTimeScale(), 30, 'incorrect getGameTimeScale() result')
 | 
					    testing.expectAlmostEqual(core.getGameTimeScale(), 30, 'incorrect getGameTimeScale() result')
 | 
				
			||||||
    testing.expectAlmostEqual(core.getSimulationTimeScale(), 1, 'incorrect getSimulationTimeScale result')
 | 
					    testing.expectAlmostEqual(core.getSimulationTimeScale(), 1, 'incorrect getSimulationTimeScale result')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,6 +61,7 @@ local function registerGlobalTest(name, description)
 | 
				
			||||||
   end)
 | 
					   end)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					registerGlobalTest('crash in lua coroutine when accessing type (#8757)')
 | 
				
			||||||
registerGlobalTest('timers')
 | 
					registerGlobalTest('timers')
 | 
				
			||||||
registerGlobalTest('teleport')
 | 
					registerGlobalTest('teleport')
 | 
				
			||||||
registerGlobalTest('getGMST')
 | 
					registerGlobalTest('getGMST')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue