Debuggers: Added inheritance testing.
This allows detailed testing of #1789 - bad Lua bindings for class inheritance.
This commit is contained in:
parent
49e59ee06b
commit
fa17fb9b80
@ -1643,6 +1643,81 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--- Monitors the state of the "inh" entity-spawning hook
|
||||||
|
-- if false, the hook is installed before the "inh" command processing
|
||||||
|
local isInhHookInstalled = false
|
||||||
|
|
||||||
|
function HandleConsoleInh(a_Split, a_FullCmd)
|
||||||
|
-- Check the param:
|
||||||
|
local kindStr = a_Split[2] or "pkArrow"
|
||||||
|
local kind = cProjectileEntity[kindStr]
|
||||||
|
if (kind == nil) then
|
||||||
|
return true, "There's no projectile kind '" .. kindStr .. "'."
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get the world to test in:
|
||||||
|
local world = cRoot:Get():GetDefaultWorld()
|
||||||
|
if (world == nil) then
|
||||||
|
return true, "Cannot test inheritance, no default world"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Install the hook, if needed:
|
||||||
|
if not(isInhHookInstalled) then
|
||||||
|
cPluginManager:AddHook(cPluginManager.HOOK_SPAWNING_ENTITY,
|
||||||
|
function (a_CBWorld, a_CBEntity)
|
||||||
|
LOG("New entity is spawning:")
|
||||||
|
LOG(" Lua type: '" .. type(a_CBEntity) .. "'")
|
||||||
|
LOG(" ToLua type: '" .. tolua.type(a_CBEntity) .. "'")
|
||||||
|
LOG(" GetEntityType(): '" .. a_CBEntity:GetEntityType() .. "'")
|
||||||
|
LOG(" GetClass(): '" .. a_CBEntity:GetClass() .. "'")
|
||||||
|
end
|
||||||
|
)
|
||||||
|
isInhHookInstalled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Create the projectile:
|
||||||
|
LOG("Creating a " .. kindStr .. " projectile in world " .. world:GetName() .. "...")
|
||||||
|
local msg
|
||||||
|
world:ChunkStay({{0, 0}},
|
||||||
|
nil,
|
||||||
|
function ()
|
||||||
|
-- Create a projectile at {8, 100, 8}:
|
||||||
|
local entityID = world:CreateProjectile(8, 100, 8, kind, nil, nil)
|
||||||
|
if (entityID < 0) then
|
||||||
|
msg = "Cannot test inheritance, projectile creation failed."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
LOG("Entity created, ID #" .. entityID)
|
||||||
|
|
||||||
|
-- Call a function on the newly created entity:
|
||||||
|
local hasExecutedCallback = false
|
||||||
|
world:DoWithEntityByID(
|
||||||
|
entityID,
|
||||||
|
function (a_CBEntity)
|
||||||
|
LOG("Projectile created and found using the DoWithEntityByID() callback")
|
||||||
|
LOG("Lua type: '" .. type(a_CBEntity) .. "'")
|
||||||
|
LOG("ToLua type: '" .. tolua.type(a_CBEntity) .. "'")
|
||||||
|
LOG("GetEntityType(): '" .. a_CBEntity:GetEntityType() .. "'")
|
||||||
|
LOG("GetClass(): '" .. a_CBEntity:GetClass() .. "'")
|
||||||
|
hasExecutedCallback = true
|
||||||
|
end
|
||||||
|
)
|
||||||
|
if not(hasExecutedCallback) then
|
||||||
|
msg = "The callback failed to execute"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
msg = "Inheritance test finished"
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
return true, msg
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function HandleConsoleLoadChunk(a_Split)
|
function HandleConsoleLoadChunk(a_Split)
|
||||||
-- Check params:
|
-- Check params:
|
||||||
local numParams = #a_Split
|
local numParams = #a_Split
|
||||||
|
@ -212,6 +212,12 @@ g_PluginInfo =
|
|||||||
HelpString = "Tests the crypto hashing functions",
|
HelpString = "Tests the crypto hashing functions",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
["inh"] =
|
||||||
|
{
|
||||||
|
Handler = HandleConsoleInh,
|
||||||
|
HelpString = "Tests the bindings of the cEntity inheritance",
|
||||||
|
},
|
||||||
|
|
||||||
["loadchunk"] =
|
["loadchunk"] =
|
||||||
{
|
{
|
||||||
Handler = HandleConsoleLoadChunk,
|
Handler = HandleConsoleLoadChunk,
|
||||||
|
Loading…
Reference in New Issue
Block a user