我用SWIG包裝C++對象在LUA使用和進出口試圖將數據傳遞給我的LUA腳本的方法,但它永遠爲「零」SWIG_NewPointerObj和價值觀始終是零
void CTestAI::UnitCreated(IUnit* unit){
lua_getglobal(L, "ai");
lua_getfield(L, -1, "UnitCreated");
swig_module_info *module = SWIG_GetModule(L);
swig_type_info *type = SWIG_TypeQueryModule(module, module, "IUnit *");
SWIG_NewPointerObj(L,unit,type,0);
lua_epcall(L, 1, 0);
}
這裏是Lua代碼:
function AI:UnitCreated(unit)
if(unit == nil) then
game:SendToConsole("I CAN HAS nil ?")
else
game:SendToConsole("I CAN HAS UNITS!!!?")
end
end
單元總是爲零。用相同的結果
void CTestAI::UnitCreated(IUnit* unit){
lua_getglobal(L, "ai");
lua_getfield(L, -1, "UnitCreated");
SWIG_NewPointerObj(L,unit,SWIGTYPE_p_IUnit,0);
lua_epcall(L, 1, 0);
}
:我已經確認並在C++代碼,單位指針是從未無效/空
我也試過。
這是爲什麼會失敗?我如何解決它?
作爲一個方面的說明,改變代碼,以便我只有函數UnitCreated在lua中,並且對C++代碼進行必要的修改,但是如果在表內調用函數 – 2010-03-09 04:30:41