OC与Lua交互,需倒入的原文件地址:frameworks/cocos2d-x/cocos/scripting/lua-bindings/manual/platform/ios
导入头文件:
#import"cocos2d.h"
USING_NS_CC;
#import"platform/ios/CCLuaObjcBridge.h"
Object-C 回调Lua函数:
LuaObjcBridge::pushLuaFunctionById( funID ); //funID是指lua传过来的函数的指针地址,一般等于1
LuaValueDictdict; //传参数给Lua,键值对
dict["openId"] =LuaValue::stringValue( [openIdUTF8String] );
dict["nickName"] =LuaValue::stringValue( [nickNameUTF8String] );
dict["imageUrl"] =LuaValue::stringValue( [imageStringUTF8String] );
LuaObjcBridge::getStack()->pushLuaValueDict( dict );
LuaObjcBridge::getStack()->executeFunction(1);
LuaObjcBridge::releaseLuaFunctionById( funID ) //调用Lua函数
Object-C 调用Lua全局函数:
cocos2d::LuaEngine::getInstance()->executeGlobalFunction("removeReqOC");//removeReqOC是Lua全局函数名