I want to transmit a int from C++ to lua , but it is a mistake at “executeCallFuncND”.
Please tell me how to use this function.
My English is poor, could you understand me ?
How did you invoke executeCallFuncND?
Could you paste moe codes?
My company can not copy codes to outer net, so I have to modify the HelloLua example.
If I insert this line in the end of “bool AppDelegate::applicationDidFinishLaunching()”
int a[ 2 ] = {0,1};
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncND(“add” , NULL , (void*)a);
I can compile it ,but can not run it successful.
What about the lua code of add and what the error looks like?
The lua code is that:
function add(tmpItem , data)
local tmpchar = string.format(“%d” , data)
cocos2d.CCLuaLog(tmochar)
end
and the error is:
Unhandled exception at 0x0056ef91 in HelloLua.exe: 0xC0000005: Access violation reading location 0x00000007.
You can insert these codes in “HelloLua” , then you may find this error.
I have another question. How can I transmit a parameter from lua to C++?
I try to use addchild(sprite , 0 , TAG) and getchildbytag(TAG) to get a CCSprite parameter ,
but if I want get a int parameter , What function I can use?
I think you should invoke the lua function by your implementation, not use executeCallFuncND. LuaEngineImpl is used for cocos2d-x to invoke the registed lua functions.
For more knowledge of commucation between c*+ and lua, please refer the offical documents of tolua**.
http://www.codenix.com/~tolua/tolua*+.html
Thank you for your help, I try to write “executeCallFuncDD” to transmit two int parameters to lua , and I succeed.
Now , I have another question.
If I want to use a superclass’s function in subclass object, how do I write in Lua?
I want to new a CCMutableArray<CCSprite*> object , but in Lua ,it only new a CCMutableArray<CCObject*> object.
I use getChildByTag() to get a child, it must be a CCObject type, not CCSprite.
You can use superclass’s function in subclass, hello.lua uses like this. What problem did you meet?
I means that If I want to create a CCMutableArray<CCSprite*> object , How do I write in lua?
In lua, it only provide three typies of CCMutableArray, but CCMutableArray<CCSprite*> is not contained.
You can put CCSprite* into CCMutableArray<CCObject*>.
No, I can’t. If I write codes like this in lua, I will get a RunTime Error.
lua code:
pTmpItem = cocos2d.CCSprite:spriteWithFile(imagePath)
Menulayer:addChild(m_pTmpItem , 0 , 0) //Menulayer is a Layer by C++ into lua
m_pItem = cocos2d.CCMutableArray_CCObject__:new(4)
tmp0 = m_pItem:getObjectAtIndex(0)
tmp0:setScale(2)