Lua function parameters from c++

Does anyone have any example code on how to pass a cocos2d-x v3.x c++ instance (eg. CCNode instance) as a paramater to a lua function?

I have noticed LuaStack::pushObject() and ScriptEngineProtocol::sendEvent() but I am unsure how these could/should be used.

Previous versions of cocos2d-x used: CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN()

I think you can refer to the handleEvent function of LuaEngine

As I understand it, this requires a nativeObject context which has a registered callback handler. I was looking to call an arbitrary global lua function. Though the correct use of handleEvent still confuses me somewhat :smiley:

Are there any tutorials, examples or even documentation for the use of LuaEngine for custom types and functions? The Lua examples provided along with cocos2d-x use one script as an entry point and everything from that point happens via cocos2d-x bindings as far as I can tell.


I have been able to work out how to send objects to lua by bypassing LuaEngine, but was hoping there was an exposed solution through LuaEngine since cocos2d-x does similar work internally:

 //get function that returns a Node
lua_getglobal(stack->getLuaState(), "luaFunc");

//call function
lua_call(stack->getLuaState(), 0, 1);

//retrieve return value
Node* child;
luaval_to_object<Node>(stack->getLuaState(), -1, "cc.Node", &child);

//remove return value from statck
lua_pop(stack->getLuaState(), 1);