Shard icon indicating copy to clipboard operation
Shard copied to clipboard

native implement Unit:UnitDamaged

Open pandaro opened this issue 8 years ago • 3 comments

<SkirmishAI: Shard dev (team 1)>: ShardCPP Warning: ai:UnitDamaged failed isfunction test, make sure it's defined in lua

pandaro avatar May 24 '17 09:05 pandaro

i have searched around for a lot of time, I can not get to the root of the problem, sorry.

pandaro avatar May 25 '17 21:05 pandaro

continuing to search: UnitDamaged is not called at all, from ai.lua , aibase.lua , unit.lua , unithandler.lua , behaviour.lua , is never called in lua so i have try to move up, in to the src but my c/c++ skill are superbasic. this is the function inside the test.cpp:

void CTestAI::UnitDamaged(IUnit* unit, IUnit* attacker, IDamage::Ptr damage){
	lua_getglobal(this->L, "ai");
	lua_getfield(this->L, -1, "UnitDamaged");
	lua_getglobal(this->L, "ai");
	SWIG_NewPointerObj(this->L,unit,unittype,0);
	SWIG_NewPointerObj(this->L,attacker,unittype,0);
	IDamage::Ptr* ptrptr = new IDamage::Ptr(damage);
	SWIG_NewPointerObj(this->L,ptrptr,damagePtr,1);
	if(lua_isfunction(this->L,-4)){
		this->lua_epcall( 3 );
	} else {
		this->game->SendToConsole( "ShardCPP Warning: ai:UnitDamaged failed isfunction test, make sure it's defined in lua" );
	}
}

i have try to skip the if statement where: if(lua_isfunction(this->L,-4)){ and call direct : this->lua_epcall( 3 );

the error give is a bit criptic:

[f=0000146] <SkirmishAI: Shard dev (team 1)>: attempt to call a table value
stack traceback:
        [C]: ?
        [C]: ?

i have then try to move me to IDamage.cpp and IDamage.h but here the situation is much complex than my actually capability can handle. I can just help in debug

pandaro avatar May 30 '17 08:05 pandaro

I suspect the stack numbers are off by 1, specifically the -4, it may need to be -5, as there are 3 parameters, a 4th referring to self and then the 5th being the function to be called

tomjn avatar May 30 '17 17:05 tomjn