#ifndef CLIENT_WFQ
#define CLIENT_WFQ
#include <string>
#include "base/CCRef.h"
class TcpSocket;
class Stream;
class ReadBuf;
class Client:public cocos2d::Ref
{
private:
TcpSocket * tcpSocket;
int _connectedCallback;
int _proxyReturnCallback;
public:
static Client* create();
void start(std::string ip,int port);
void send(Stream * stream);
void recv();
void update(float t);
void onConnected();
void registerConnectedCallback(int handler);
void onProxyReturn(ReadBuf * buf);
void registerProxyReturnCallback(int handler);
};
#endif
对于函数
void registerConnectedCallback(int handler);
传入的是一个lua函数,如果按照正常的方法生成c++和lua的绑定文件,会报错,说类型不正确
找到绑定文件的
int lua_cocos2dx_custom_client_Client_registerConnectedCallback(lua_State* tolua_S)
将类型判断注释掉,并且手动转为函数类型LUA_FUNCTION
需要添加头文件
CCLuaValue.h
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
int arg0;
/*ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "Client:registerConnectedCallback");
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_custom_client_Client_registerConnectedCallback'", nullptr);
return 0;
}*/
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
cobj->registerConnectedCallback(handler);
lua_settop(tolua_S, 1);
return 1;
}
对于函数
toluafix_ref_function
具体的参数意义暂时没搞清楚,之后再探究竟
toluafix_ref_function(tolua_S,2,0);
这里的参数是不用变的,都是2,0这样