lua WebSocket

lua WebSocket
0.0 0


Although I can’t find any .pkg file for WebSocket interface of lua, functiontolua_web_socket_open* in Lua_web_socket.cpp will show this.
And for function sendBinaryMsg, why I can’t pass a string in lua but table? String is more suitable for bytes buffer, not table.


I read the code of tolua_Cocos2d_WebSocket_sendBinary00 and tolua_Cocos2d_WebSocket_sendBinaryMsg00, maybe the author doubt tolua_tostring can’t return a correct pointer if lua string contains zero. From lua manual[1], function lua_tolstring can return a right point to lua string and a correct lenght of it always.
Then I add a function named sendBinary to send binary buffer from lua using lua string.

// ref tolua_tostring and support string size return.
const char* tolua_tostring(lua_State* L, int narg, const char* def, size_t* size)
size = 0;
return lua_gettop < abs ? def : lua_tolstring;
// ref tolua_Cocos2d_WebSocket_sendTextMsg00 to implement.
method: sendBinary of class WebSocket /
#ifndef TOLUA_DISABLE_tolua_Cocos2d_WebSocket_sendBinary00
static int tolua_Cocos2d_WebSocket_sendBinary00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,“WebSocket”,0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
goto tolua_lerror;
LuaWebSocket* self = (LuaWebSocket**) tolua_tousertype;
size_t size;
const char pData = tolua_tostring);
if {
self->sendpData, size);
return 0;
return 0;
#endif //#ifndef TOLUA_DISABLE

// add this line at somewhere of**Lua_web_socket.cpp* bottom, you know.
tolua_function(tolua_S, “sendBinary”, tolua_Cocos2d_WebSocket_sendBinary00);


MORE: cocos has pkg file for Lua_web_socket will be better.