mirror of https://github.com/axmolengine/axmol.git
Remove websockets, sync lua bindings.
This commit is contained in:
parent
97e81e8180
commit
af22abc2a8
|
@ -1121,56 +1121,6 @@ int lua_cocos2dx_Texture2D_getMaxT(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_setAlphaTexture(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::Texture2D* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.Texture2D",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::Texture2D*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Texture2D_setAlphaTexture'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 1)
|
||||
{
|
||||
cocos2d::Texture2D* arg0;
|
||||
|
||||
ok &= luaval_to_object<cocos2d::Texture2D>(tolua_S, 2, "cc.Texture2D",&arg0, "cc.Texture2D:setAlphaTexture");
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Texture2D_setAlphaTexture'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->setAlphaTexture(arg0);
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Texture2D:setAlphaTexture",argc, 1);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Texture2D_setAlphaTexture'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_getStringForFormat(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -1418,53 +1368,6 @@ int lua_cocos2dx_Texture2D_getPixelsHigh(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_getAlphaTextureName(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::Texture2D* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.Texture2D",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::Texture2D*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Texture2D_getAlphaTextureName'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 0)
|
||||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Texture2D_getAlphaTextureName'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
bool ret = cobj->getAlphaTextureName();
|
||||
tolua_pushboolean(tolua_S,(bool)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Texture2D:getAlphaTextureName",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Texture2D_getAlphaTextureName'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_getBitsPerPixelForFormat(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -2178,53 +2081,6 @@ int lua_cocos2dx_Texture2D_generateMipmap(lua_State* tolua_S)
|
|||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_getAlphaTexture(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::Texture2D* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.Texture2D",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::Texture2D*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Texture2D_getAlphaTexture'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
if (argc == 0)
|
||||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Texture2D_getAlphaTexture'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::Texture2D* ret = cobj->getAlphaTexture();
|
||||
object_to_luaval<cocos2d::Texture2D>(tolua_S, "cc.Texture2D",(cocos2d::Texture2D*)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Texture2D:getAlphaTexture",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Texture2D_getAlphaTexture'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_Texture2D_getPixelFormat(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
|
@ -2751,13 +2607,11 @@ int lua_register_cocos2dx_Texture2D(lua_State* tolua_S)
|
|||
tolua_beginmodule(tolua_S,"Texture2D");
|
||||
tolua_function(tolua_S,"new",lua_cocos2dx_Texture2D_constructor);
|
||||
tolua_function(tolua_S,"getMaxT",lua_cocos2dx_Texture2D_getMaxT);
|
||||
tolua_function(tolua_S,"setAlphaTexture",lua_cocos2dx_Texture2D_setAlphaTexture);
|
||||
tolua_function(tolua_S,"getStringForFormat",lua_cocos2dx_Texture2D_getStringForFormat);
|
||||
tolua_function(tolua_S,"initWithImage",lua_cocos2dx_Texture2D_initWithImage);
|
||||
tolua_function(tolua_S,"getMaxS",lua_cocos2dx_Texture2D_getMaxS);
|
||||
tolua_function(tolua_S,"hasPremultipliedAlpha",lua_cocos2dx_Texture2D_hasPremultipliedAlpha);
|
||||
tolua_function(tolua_S,"getPixelsHigh",lua_cocos2dx_Texture2D_getPixelsHigh);
|
||||
tolua_function(tolua_S,"getAlphaTextureName",lua_cocos2dx_Texture2D_getAlphaTextureName);
|
||||
tolua_function(tolua_S,"getBitsPerPixelForFormat",lua_cocos2dx_Texture2D_getBitsPerPixelForFormat);
|
||||
tolua_function(tolua_S,"setMaxS",lua_cocos2dx_Texture2D_setMaxS);
|
||||
tolua_function(tolua_S,"initWithString",lua_cocos2dx_Texture2D_initWithString);
|
||||
|
@ -2769,7 +2623,6 @@ int lua_register_cocos2dx_Texture2D(lua_State* tolua_S)
|
|||
tolua_function(tolua_S,"setAliasTexParameters",lua_cocos2dx_Texture2D_setAliasTexParameters);
|
||||
tolua_function(tolua_S,"setAntiAliasTexParameters",lua_cocos2dx_Texture2D_setAntiAliasTexParameters);
|
||||
tolua_function(tolua_S,"generateMipmap",lua_cocos2dx_Texture2D_generateMipmap);
|
||||
tolua_function(tolua_S,"getAlphaTexture",lua_cocos2dx_Texture2D_getAlphaTexture);
|
||||
tolua_function(tolua_S,"getPixelFormat",lua_cocos2dx_Texture2D_getPixelFormat);
|
||||
tolua_function(tolua_S,"getBackendTexture",lua_cocos2dx_Texture2D_getBackendTexture);
|
||||
tolua_function(tolua_S,"getContentSizeInPixels",lua_cocos2dx_Texture2D_getContentSizeInPixels);
|
||||
|
|
|
@ -1,545 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#include "scripting/lua-bindings/manual/network/Lua_web_socket.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "scripting/lua-bindings/manual/tolua_fix.h"
|
||||
|
||||
#include "scripting/lua-bindings/manual/CCLuaStack.h"
|
||||
#include "scripting/lua-bindings/manual/CCLuaValue.h"
|
||||
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
||||
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
||||
#include "scripting/lua-bindings/manual/cocos2d/LuaScriptHandlerMgr.h"
|
||||
#include "scripting/deprecated/CCString.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
static int SendBinaryMessageToLua(int nHandler,const unsigned char* pTable,int nLength)
|
||||
{
|
||||
if (NULL == pTable || nHandler <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL == ScriptEngineManager::getInstance()->getScriptEngine()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaStack *pStack = LuaEngine::getInstance()->getLuaStack();
|
||||
if (NULL == pStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_State *tolua_s = pStack->getLuaState();
|
||||
if (NULL == tolua_s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nRet = 0;
|
||||
LuaValueArray array;
|
||||
for (int i = 0 ; i < nLength; i++) {
|
||||
LuaValue value = LuaValue::intValue(pTable[i]);
|
||||
array.push_back(value);
|
||||
}
|
||||
|
||||
pStack->pushLuaValueArray(array);
|
||||
nRet = pStack->executeFunctionByHandler(nHandler, 1);
|
||||
pStack->clean();
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
LuaWebSocket::~LuaWebSocket()
|
||||
{
|
||||
ScriptHandlerMgr::getInstance()->removeObjectAllHandlers((void*)this);
|
||||
}
|
||||
|
||||
void LuaWebSocket::onOpen(WebSocket* ws)
|
||||
{
|
||||
LuaWebSocket* luaWs = dynamic_cast<LuaWebSocket*>(ws);
|
||||
if (NULL != luaWs) {
|
||||
int nHandler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_OPEN);
|
||||
if (0 != nHandler) {
|
||||
CommonScriptData data(nHandler,"");
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LuaWebSocket::onClose(WebSocket* ws)
|
||||
{
|
||||
LuaWebSocket* luaWs = dynamic_cast<LuaWebSocket*>(ws);
|
||||
if (NULL != luaWs) {
|
||||
int nHandler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_CLOSE);
|
||||
if (0 != nHandler)
|
||||
{
|
||||
CommonScriptData data(nHandler,"");
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LuaWebSocket::onError(WebSocket* ws, const WebSocket::ErrorCode& error)
|
||||
{
|
||||
LuaWebSocket* luaWs = dynamic_cast<LuaWebSocket*>(ws);
|
||||
if (NULL != luaWs) {
|
||||
int nHandler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this,ScriptHandlerMgr::HandlerType::WEBSOCKET_ERROR);
|
||||
if (0 != nHandler)
|
||||
{
|
||||
CommonScriptData data(nHandler,"");
|
||||
ScriptEvent event(kCommonEvent,(void*)&data);
|
||||
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
static int tolua_collect_WebSocket (lua_State* tolua_S)
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*) tolua_tousertype(tolua_S,1,0);
|
||||
Mtolua_delete(self);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/* function to release collected object via destructor */
|
||||
static void tolua_reg_Web_Socket_type(lua_State* tolua_S)
|
||||
{
|
||||
tolua_usertype(tolua_S, "cc.WebSocket");
|
||||
}
|
||||
|
||||
/* method: create of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_create00
|
||||
static int tolua_Cocos2d_WebSocket_create00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
int argumentCount = lua_gettop(tolua_S);
|
||||
if (argumentCount >= 2)
|
||||
{
|
||||
std::string url;
|
||||
std::vector<std::string> protocols;
|
||||
std::string caCertPath;
|
||||
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,2,0,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
if (argumentCount == 3)
|
||||
{
|
||||
if (lua_istable(tolua_S, 3))
|
||||
{
|
||||
luaval_to_std_vector_string(tolua_S, 3, &protocols, "cc.WebSocket.create");
|
||||
}
|
||||
else if (lua_isstring(tolua_S, 3))
|
||||
{
|
||||
luaval_to_std_string(tolua_S, 3, &caCertPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
luaL_error(tolua_S, "The second parameter should be a table contains protocols of string type or a string indicates ca certificate path!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if (argumentCount == 4)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
if (!tolua_istable(tolua_S, 3, 0, &tolua_err)
|
||||
|| !tolua_isstring(tolua_S, 4, 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
luaval_to_std_vector_string(tolua_S, 3, &protocols, "cc.WebSocket.create");
|
||||
luaval_to_std_string(tolua_S, 4, &caCertPath);
|
||||
}
|
||||
|
||||
luaval_to_std_string(tolua_S, 2, &url);
|
||||
|
||||
LuaWebSocket *wSocket = new (std::nothrow) LuaWebSocket();
|
||||
wSocket->init(*wSocket, url, &protocols, caCertPath);
|
||||
tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket");
|
||||
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
|
||||
return 1;
|
||||
}
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'create'.",&tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: createByAProtocol of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_createByAProtocol00
|
||||
static int tolua_Cocos2d_WebSocket_createByAProtocol00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,3,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,4,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const char *urlName = ((const char*) tolua_tostring(tolua_S,2,0));
|
||||
const char *protocol = ((const char*) tolua_tostring(tolua_S,3,0));
|
||||
std::vector<std::string> protocols;
|
||||
protocols.push_back(protocol);
|
||||
LuaWebSocket *wSocket = new (std::nothrow) LuaWebSocket();
|
||||
wSocket->init(*wSocket, urlName,&protocols);
|
||||
tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket");
|
||||
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'createByAProtocol'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: createByAProtocol of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_createByProtocolArray00
|
||||
static int tolua_Cocos2d_WebSocket_createByProtocolArray00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertable(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isusertable(tolua_S,3,"CCArray",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,4,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const char *urlName = ((const char*) tolua_tostring(tolua_S,2,0));
|
||||
__Array* protocolArray = ((__Array*) tolua_tousertype(tolua_S,3,0));
|
||||
std::vector<std::string> protocols;
|
||||
if (NULL != protocolArray) {
|
||||
Ref* pObj = NULL;
|
||||
CCARRAY_FOREACH(protocolArray, pObj)
|
||||
{
|
||||
__String* pStr = static_cast<__String*>(pObj);
|
||||
if (NULL != pStr) {
|
||||
protocols.push_back(pStr->getCString());
|
||||
}
|
||||
}
|
||||
}
|
||||
LuaWebSocket *wSocket = new (std::nothrow) LuaWebSocket();
|
||||
wSocket->init(*wSocket, urlName,&protocols);
|
||||
tolua_pushusertype(tolua_S,(void*)wSocket,"cc.WebSocket");
|
||||
tolua_register_gc(tolua_S,lua_gettop(tolua_S));
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'createByProtocolArray'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: getReadyState of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_getReadyState00
|
||||
static int tolua_Cocos2d_WebSocket_getReadyState00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket *self = (LuaWebSocket*)tolua_tousertype(tolua_S,1,0);
|
||||
int tolua_ret = -1;
|
||||
if (NULL != self) {
|
||||
tolua_ret = (int)self->getReadyState();
|
||||
}
|
||||
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
|
||||
}
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'getReadyState'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
|
||||
/* method: close of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_close00
|
||||
static int tolua_Cocos2d_WebSocket_close00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
self->closeAsync();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'getReadyState'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
/* method: sendString of class WebSocket */
|
||||
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_sendString00
|
||||
static int tolua_Cocos2d_WebSocket_sendString00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S, 1, "cc.WebSocket", 0, &tolua_err) ||
|
||||
!tolua_isstring(tolua_S, 2, 0, &tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S, 3, &tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*) tolua_tousertype(tolua_S,1,0);
|
||||
size_t size = 0;
|
||||
const char* data = (const char*) lua_tolstring(tolua_S, 2, &size);
|
||||
if ( NULL == data)
|
||||
return 0;
|
||||
|
||||
if (strlen(data) != size)
|
||||
{
|
||||
self->send((const unsigned char*)data, (unsigned int)size);
|
||||
}
|
||||
else
|
||||
{
|
||||
self->send(data);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'sendString'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif //#ifndef TOLUA_DISABLE
|
||||
|
||||
static int websocket_url_getter(lua_State* L)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L, 1, "cc.WebSocket", 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, self->getUrl().c_str());
|
||||
return 1;
|
||||
}
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'sendString'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int websocket_protocol_getter(lua_State* L)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(L, 1, "cc.WebSocket", 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, self->getProtocol().c_str());
|
||||
return 1;
|
||||
}
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'sendString'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
TOLUA_API int tolua_web_socket_open(lua_State* tolua_S){
|
||||
tolua_open(tolua_S);
|
||||
tolua_reg_Web_Socket_type(tolua_S);
|
||||
tolua_module(tolua_S,"cc",0);
|
||||
tolua_beginmodule(tolua_S,"cc");
|
||||
#ifdef __cplusplus
|
||||
tolua_cclass(tolua_S,"WebSocket","cc.WebSocket","",tolua_collect_WebSocket);
|
||||
#else
|
||||
tolua_cclass(tolua_S,"WebSocket","cc.WebSocket","",NULL);
|
||||
#endif
|
||||
tolua_beginmodule(tolua_S,"WebSocket");
|
||||
tolua_function(tolua_S, "create", tolua_Cocos2d_WebSocket_create00);
|
||||
tolua_function(tolua_S, "createByAProtocol", tolua_Cocos2d_WebSocket_createByAProtocol00);
|
||||
tolua_function(tolua_S, "createByProtocolArray", tolua_Cocos2d_WebSocket_createByProtocolArray00);
|
||||
tolua_function(tolua_S, "getReadyState", tolua_Cocos2d_WebSocket_getReadyState00);
|
||||
tolua_function(tolua_S, "close", tolua_Cocos2d_WebSocket_close00);
|
||||
tolua_function(tolua_S, "sendString", tolua_Cocos2d_WebSocket_sendString00);
|
||||
tolua_variable(tolua_S, "url", websocket_url_getter, nullptr);
|
||||
tolua_variable(tolua_S, "protocol", websocket_protocol_getter, nullptr);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_endmodule(tolua_S);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tolua_Cocos2d_WebSocket_registerScriptHandler00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,3,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,4,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
int handler = ( toluafix_ref_function(tolua_S,2,0));
|
||||
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType)((int)tolua_tonumber(tolua_S,3,0) + (int)ScriptHandlerMgr::HandlerType::WEBSOCKET_OPEN);
|
||||
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, handlerType);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int tolua_Cocos2d_WebSocket_unregisterScriptHandler00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"cc.WebSocket",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaWebSocket* self = (LuaWebSocket*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType)((int)tolua_tonumber(tolua_S,2,0) + (int)ScriptHandlerMgr::HandlerType::WEBSOCKET_OPEN);
|
||||
|
||||
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, handlerType);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'unregisterScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
TOLUA_API int register_web_socket_manual(lua_State* tolua_S)
|
||||
{
|
||||
if (nullptr == tolua_S)
|
||||
return 0 ;
|
||||
|
||||
lua_pushstring(tolua_S,"cc.WebSocket");
|
||||
lua_rawget(tolua_S,LUA_REGISTRYINDEX);
|
||||
if (lua_istable(tolua_S,-1))
|
||||
{
|
||||
lua_pushstring(tolua_S,"registerScriptHandler");
|
||||
lua_pushcfunction(tolua_S,tolua_Cocos2d_WebSocket_registerScriptHandler00);
|
||||
lua_rawset(tolua_S,-3);
|
||||
lua_pushstring(tolua_S,"unregisterScriptHandler");
|
||||
lua_pushcfunction(tolua_S,tolua_Cocos2d_WebSocket_unregisterScriptHandler00);
|
||||
lua_rawset(tolua_S,-3);
|
||||
}
|
||||
lua_pop(tolua_S, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif//(CC_TARGET_PLATFORM == CC_PLATFORM_IOS ...
|
|
@ -1,65 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#ifndef __LUA_WEB_SOCKET_H__
|
||||
#define __LUA_WEB_SOCKET_H__
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "tolua++.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "network/WebSocket.h"
|
||||
|
||||
///@cond
|
||||
class LuaWebSocket: public cocos2d::network::WebSocket,public cocos2d::network::WebSocket::Delegate
|
||||
{
|
||||
public:
|
||||
virtual ~LuaWebSocket();
|
||||
virtual void onOpen(WebSocket* ws) override;
|
||||
virtual void onMessage(WebSocket* ws, const WebSocket::Data& data) override;
|
||||
virtual void onClose(WebSocket* ws) override;
|
||||
virtual void onError(WebSocket* ws, const WebSocket::ErrorCode& error) override;
|
||||
|
||||
enum WebSocketScriptHandlerType
|
||||
{
|
||||
kWebSocketScriptHandlerOpen,
|
||||
kWebSocketScriptHandlerMessage,
|
||||
kWebSocketScriptHandlerClose,
|
||||
kWebSocketScriptHandlerError,
|
||||
};
|
||||
};
|
||||
|
||||
TOLUA_API int tolua_web_socket_open(lua_State* tolua_S);
|
||||
TOLUA_API int register_web_socket_manual(lua_State* tolua_S);
|
||||
///@endcond
|
||||
|
||||
#endif //(CC_TARGET_PLATFORM == CC_PLATFORM_IOS ...
|
||||
|
||||
#endif //__LUA_WEB_SOCKET_H__
|
|
@ -28,9 +28,6 @@ extern "C" {
|
|||
#include "scripting/lua-bindings/manual/network/lua_extensions.h"
|
||||
#endif
|
||||
}
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#include "scripting/lua-bindings/manual/network/Lua_web_socket.h"
|
||||
#endif
|
||||
|
||||
#include "scripting/lua-bindings/manual/network/lua_xml_http_request.h"
|
||||
#include "scripting/lua-bindings/manual/network/lua_downloader.h"
|
||||
|
@ -45,12 +42,7 @@ int register_network_module(lua_State* L)
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
luaopen_lua_extensions(L);
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
tolua_web_socket_open(L);
|
||||
register_web_socket_manual(L);
|
||||
#endif
|
||||
|
||||
|
||||
register_xml_http_request(L);
|
||||
register_downloader(L);
|
||||
}
|
||||
|
|
|
@ -229,17 +229,14 @@ static int lua_downloader_setOnTaskProgress(lua_State *L)
|
|||
luaL_argcheck(L, lua_isfunction(L, 2), 2, "should be a function");
|
||||
saveCallback(L, d, "setOnTaskProgress");
|
||||
|
||||
d->setOnTaskProgress([d, L](const DownloadTask &task,
|
||||
int64_t bytesReceived,
|
||||
int64_t totalBytesReceived,
|
||||
int64_t totalBytesExpected) {
|
||||
d->setOnTaskProgress([d, L](const DownloadTask &task) {
|
||||
int ret = getCallback(L, d, "setOnTaskProgress"); //stack callbackfn
|
||||
if (ret)
|
||||
{
|
||||
pushTaskTable(L, task); //stack callbackfn, task
|
||||
lua_pushnumber(L, (lua_Number)bytesReceived);
|
||||
lua_pushnumber(L, (lua_Number)totalBytesReceived);
|
||||
lua_pushnumber(L, (lua_Number)totalBytesExpected);
|
||||
lua_pushnumber(L, (lua_Number)task.progressInfo.bytesReceived);
|
||||
lua_pushnumber(L, (lua_Number)task.progressInfo.totalBytesReceived);
|
||||
lua_pushnumber(L, (lua_Number)task.progressInfo.totalBytesExpected);
|
||||
if (lua_pcall(L, 4, 0, 0) != 0)
|
||||
{
|
||||
lua_pop(L, 1); // remove callback or nil
|
||||
|
|
Loading…
Reference in New Issue