In c**, we can pass data when postNotification:
<pre>
CCNotificationCenter::sharedNotificationCenter~~>postNotification);
</pre>
And get it in callback:
<pre>
void MyObject::callback
{
CCString * myData = pObj;
// …
}
</pre>
But this cannot work in lua, I found that postNotification don’t pass the second parameter to script engine.
<pre>
void CCNotificationCenter::postNotification
{
CCArray* ObserversCopy = CCArray::createWithCapacity);
ObserversCopy~~>addObjectsFromArray;
CCObject* obj = NULL;
CCARRAY_FOREACH
{
CCNotificationObserver* observer = obj;
if
continue;
if ) && object || observer->getObject() NULL || object == NULL))
{
if )
{
CCScriptEngineProtocol* engine = CCScriptEngineManager::sharedManager~~>getScriptEngine;
engine~~>executeNotificationEvent; // <——— “object” not used
}
else
{
observer->performSelector;
}
}
}
}
</pre>
I can pass data from lua to c** using postNotification:
You can extend the postNotification function by increasing the input params like this: int executeNotificationEvent(NotificationCenter* pNotificationCenter, const char* pszName,CCObject *object = NULL);
and modify the implementation of this function.
You can extend the postNotification function by increasing the input params like this: int executeNotificationEvent(NotificationCenter* pNotificationCenter, const char* pszName,CCObject *object = NULL);
and modify the implementation of this function.
But, must modify CCNotificationCenter::postNotification to use it, how to extend CCNotificationCenter transparently?
it seems that this issue was not fixed in the latest version 2.2.2 and 3.0beta. i also wanna use CCNotificationCenter in my LUA script to accept message with a CCObject* parameter from cpp code…