userdata是lua提供给开发者自定义C/C++数据结构的一套api,他能够在C/C++层映射内存空间,使我们的程序能够更加的灵活。下面我就来介绍一下userdata是如何绑定C/C++对象的。
首先定义构造函数如下
#define HTTP_REQUEST_META_NAME "HttpRequest"
class HttpRequestWrapper {
public:
HttpRequestWrapper(const char*bind,const char*host, int port){
}
static int create(lua_State* L) {
const char* bind = lua_tostring(L, 2);
const char* host = lua_tostring(L, 3);
int port = (int) lua_tointeger(L, 4);
w = new HttpRequestWrapper(bind,host,port);
if (w == NULL)
goto FAIL;
void **u = (void**)