Forum > Lua Binding > Best way to pass information between C++ and Lua when doing callback?

Best way to pass information between C++ and Lua when doing callback?

By krystian Posted 2012-01-25 07:20 Comments 1
  • Posts: 44


I’ve got a problem regarding passing information to lua functions from c++ when doing executeCallFunc*.
It’s all fine when I have to pass integers, as I can use CCNode and tag for example.
The trouble starts when I have to pass a string for example.
So I’ve tried using userData on CCNode to pass this information [that’s a hack, I know, but I couldn’t find any other way to do so], but all I get in Lua is userdata :/

CCNode *tempNode = CCNode::node();
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN(functionNameOk.c_str(), tempNode);

and in Lua:

function testString(node)
  ogsLog("node:", node)
  ogsLog("wooohoooo string passed!", node:getUserData())

I get:

Cocos2d: node:      userdata: 0xeb49e94     
Cocos2d: wooohoooo string passed!       userdata: 0xeb40e8c 

Damn :/

I would appreciate if someone could point me in right direction :/ I’m sure I’m missing something obvious.

  • Posts: 1

#1 RE: 2012-03-04 22:32


Is there a way to pass some data from c*+ to the lua script?
For example, there is a object in c*+ named SomeDataForLua with int fields someData1 and someData2.
Is it possible to send this to the lua script from c++?

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps