void LuaWebSocket::onMessage(WebSocket* ws, const WebSocket::Data& data) { LuaWebSocket* luaWs = dynamic_cast<LuaWebSocket*>(ws); if (NULL != luaWs) { if (data.isBinary) { int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_MESSAGE); if (0 != handler) { SendBinaryMessageToLua(handler, (const unsigned char*)data.bytes, (int)data.len); } } else{ int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_MESSAGE); if (0 != handler) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); if (nullptr != stack) { stack->pushString(data.bytes,(int)data.len); stack->executeFunctionByHandler(handler, 1); } } } } }
LUA_STRING Crypto::encodingBase64Lua(bool isDecoding, const char* input, int inputLength) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); int bufferSize = isDecoding ? Base64decode_len(input) : Base64encode_len(inputLength); char *buffer = bufferSize ? (char*)malloc(bufferSize) : NULL; int size = 0; if (buffer) { size = isDecoding ? Base64decode(buffer, input) : Base64encode(buffer, input, inputLength); } if (size) { stack->pushString(buffer, size); } else { stack->pushNil(); } if (buffer) { free(buffer); } return 1; }
cocos2d::LUA_STRING Crypto::cryptAES256Lua(bool isDecrypt, const char* input, int inputLength, const char* key, int keyLength) { LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); if (getAES256KeyLength() == 0) { stack->pushNil(); return 1; } int bufferSize = inputLength + getAES256KeyLength(); void* buffer = malloc(bufferSize); int dataUsed = cryptAES256(isDecrypt, (unsigned char*)input, inputLength, (unsigned char*)buffer, bufferSize, (unsigned char*)key, keyLength); if (dataUsed > 0) { stack->pushString(static_cast<const char*>(buffer), dataUsed); } else { stack->pushNil(); } free(buffer); return 1; }
void flurrySessionDidCreateWithInfo(std::map<std::string, std::string>& info) { std::string jsonStr = map2JsonString(info); LuaStack* stack = LUAENGINE->getLuaStack(); stack->pushString(jsonStr.c_str()); stack->executeFunctionByHandler(mLuaHandler, 1); }
int lua_game_manager_Http_get(lua_State* tolua_S) { int argc = 0; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif game::manager::Http* cobj = (game::manager::Http*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 //if (!tolua_isusertable(tolua_S,1,"game.manager.Http",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; if (argc >= 1) { if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_game_manager_Http_get'", nullptr); return 0; } std::string url,postData; ok &= luaval_to_std_string(tolua_S, 2,&url, "game.manager.Http"); if(argc >= 2) { ok &= luaval_to_std_string(tolua_S, 3,&postData, "game.manager.Http"); } RequestCompleteCallBack completeCallback = nullptr; if (argc >= 3) { LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,4,0)); completeCallback = [=](const char* szBuffer){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushString(szBuffer); stack->executeFunctionByHandler(handler, 1); stack->clean(); }; } cobj->get(url,postData,completeCallback); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Node:create",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_game_manager_Http_get'.",&tolua_err); #endif return 0; }
LUA_STRING Crypto::MD5Lua(const char* inputStr, bool isRawOutput) { unsigned char buffer[MD5_BUFFER_LENGTH]; char* input = (char*)inputStr; MD5(static_cast<void*>(input), (int)strlen(input), buffer); LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); if (isRawOutput) { stack->pushString((char*)buffer, MD5_BUFFER_LENGTH); } else { char* hex = bin2hex(buffer, MD5_BUFFER_LENGTH); stack->pushString(hex); delete[] hex; } return 1; }
int lua_cocos2dx_audioengine_AudioEngine_setFinishCallback(lua_State* tolua_S) { int argc = 0; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertable(tolua_S,1,"ccexp.AudioEngine",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; if (argc == 2) { int arg0; ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccexp.AudioEngine:setFinishCallback"); #if COCOS2D_DEBUG >= 1 if (!toluafix_isfunction(tolua_S,3,"LUA_FUNCTION",0,&tolua_err)) { goto tolua_lerror; } #endif LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0)); cocos2d::experimental::AudioEngine::setFinishCallback(arg0, [handler](int audioID, std::string filePath){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushInt(audioID); stack->pushString(filePath.c_str()); stack->executeFunctionByHandler(handler, 2); LuaEngine::getInstance()->removeScriptHandler(handler); }); return 0; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.AudioEngine:setFinishCallback",argc, 2); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_audioengine_AudioEngine_setFinishCallback'.",&tolua_err); #endif return 0; }
LUA_STRING Crypto::MD5FileLua(const char* path) { unsigned char buffer[MD5_BUFFER_LENGTH]; MD5File(path, buffer); LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); char* hex = bin2hex(buffer, MD5_BUFFER_LENGTH); stack->pushString(hex); delete[] hex; return 1; }
LUA_STRING Crypto::MD5StringLua(char* input, int inputLength) { unsigned char buffer[MD5_BUFFER_LENGTH]; MD5(static_cast<void*>(input), inputLength, buffer); LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); char* hex = bin2hex(buffer, MD5_BUFFER_LENGTH); stack->pushString(hex); delete[] hex; return 1; }
int HelperFunc::getFileData(const char *pPathFile) { unsigned long size; unsigned char* buf = HelperFunc::getFileData(pPathFile, "rb", &size); LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->clean(); if (buf) { stack->pushString((const char*)(buf), (int)size); delete buf; } else { stack->pushNil(); } return 1; }
void NBGCCBReader::completedAnimationSequenceNamed(const char *name) { if (luaHandler_animationCallback > 0) { auto engine = LuaEngine::getInstance(); LuaStack* stack = engine->getLuaStack(); stack->pushString(name); stack->executeFunctionByHandler(luaHandler_animationCallback, 1); stack->clean(); } if (animCompletedCallback != nullptr) { animCompletedCallback(name); } }
bool NBGCCBReader::onAssignCCBMemberVariable(Ref * pTarget, const char * pMemberVariableName, Node * node) { if (pTarget == this) { if (luaHandler_memberVarSetter > 0) { auto engine = LuaEngine::getInstance(); LuaStack* stack = engine->getLuaStack(); stack->pushString(pMemberVariableName); stack->pushObject(node, "cc.Node"); stack->executeFunctionByHandler(luaHandler_memberVarSetter, 2); stack->clean(); } if (assignMemVarCallback != nullptr) { return assignMemVarCallback(pTarget, pMemberVariableName, node); } } return false; }
int lua_game_manager_Http_pushDownLoad(lua_State* tolua_S) { int argc = 0; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif game::manager::Http* cobj = (game::manager::Http*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 //if (!tolua_isusertable(tolua_S,1,"game.manager.Http",0,&tolua_err)) goto tolua_lerror; #endif argc = lua_gettop(tolua_S) - 1; if (argc >= 1) { if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_game_manager_Http_get'", nullptr); return 0; } std::string url; ok &= luaval_to_std_string(tolua_S, 2,&url, "game.manager.Http"); RequestCompleteCallBack completeCallback = nullptr; if (argc >= 2) { LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,3,0)); completeCallback = [=](const char* szBuffer){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushString(szBuffer); stack->executeFunctionByHandler(handler, 1); stack->clean(); }; } DownLoadProgressCallBack progressCallBack = nullptr; if (argc >= 3) { LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,4,0)); progressCallBack = [=](double total,double progress){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushFloat(total); stack->pushFloat(progress); stack->executeFunctionByHandler(handler, 2); stack->clean(); }; } DownErrorCallBack errorCallBack = nullptr; if (argc >= 3) { LUA_FUNCTION handler = ( toluafix_ref_function(tolua_S,5,0)); errorCallBack = [=](Downloader::Error error){ LuaStack* stack = LuaEngine::getInstance()->getLuaStack(); stack->pushInt((int)error.code); stack->pushString(error.message.c_str(),error.message.size()); stack->executeFunctionByHandler(handler, 2); stack->clean(); }; } cobj->pushDownLoad(url,completeCallback,progressCallBack,errorCallBack); lua_settop(tolua_S, 1); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Node:create",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_game_manager_Http_get'.",&tolua_err); #endif return 0; }