diff options
| author | Alexander Pickering <alex@cogarr.net> | 2020-08-08 19:53:44 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2020-08-08 19:53:44 -0400 |
| commit | 23e08942472787a2df47f2ae5ea1a29f8cbfd576 (patch) | |
| tree | 55efe646ce54cd1441ff06c001e57fa7a94d159c | |
| parent | 27ece5603fc0cde89183ceb61f915fa64fef1061 (diff) | |
| download | lua-nng-23e08942472787a2df47f2ae5ea1a29f8cbfd576.tar.gz lua-nng-23e08942472787a2df47f2ae5ea1a29f8cbfd576.tar.bz2 lua-nng-23e08942472787a2df47f2ae5ea1a29f8cbfd576.zip | |
Removed print from aio
Removed multiple debugging print statements for asyncronous functions.
| -rw-r--r-- | src/lua-nng-aio.c | 102 | ||||
| -rw-r--r-- | src/lua-nng.c | 224 |
2 files changed, 249 insertions, 77 deletions
diff --git a/src/lua-nng-aio.c b/src/lua-nng-aio.c index fa3db33..a4f8944 100644 --- a/src/lua-nng-aio.c +++ b/src/lua-nng-aio.c @@ -37,12 +37,12 @@ struct lnng_aio{ };
void lcallback(void *lfaa){
- printf("aio callback running\n");
+ /*printf("aio callback running\n");*/
struct lnng_aio *l = (struct lnng_aio*)lfaa;
lua_State *L = l->L;
- printf("At the beginning we have: %d\n",lua_gettop(L));
+ /*printf("At the beginning we have: %d\n",lua_gettop(L));*/
for(int i = 1; i <= lua_gettop(L); i++){
- printf("-%d - %s\n",i,lua_typename(L,lua_type(L,-i)));
+ /*printf("-%d - %s\n",i,lua_typename(L,lua_type(L,-i)));*/
lua_getglobal(L,"print");
lua_pushvalue(L,i);
lua_call(L,1,0);
@@ -50,25 +50,25 @@ void lcallback(void *lfaa){ lua_getglobal(L,"table");//{table}
lua_pushcfunction(L,traceback);//{table},traceback()
lua_rawgeti(L,LUA_REGISTRYINDEX, l->func);//{table},traceback(),callb()
- printf("foo\n");
+ /*printf("foo\n");*/
lua_getfield(L,-3,"unpack");//{table},traceback(),callb(),table.unpack()
- printf("unpacked\n");
- printf("unpack, -1 - %s\n",lua_typename(L,lua_type(L,-1)));
- printf("Args was: %d\n",l->args);
+ /*printf("unpacked\n");*/
+ /*printf("unpack, -1 - %s\n",lua_typename(L,lua_type(L,-1)));*/
+ /*printf("Args was: %d\n",l->args);*/
lua_rawgeti(L,LUA_REGISTRYINDEX, l->args);//{table},traceback(),callb(),table.unpack(),{args}
- printf("got args\n");
- printf("-2 - %s\n",lua_typename(L,lua_type(L,-2)));
- printf("-1 - %s\n",lua_typename(L,lua_type(L,-1)));
+ /*printf("got args\n");*/
+ /*printf("-2 - %s\n",lua_typename(L,lua_type(L,-2)));*/
+ /*printf("-1 - %s\n",lua_typename(L,lua_type(L,-1)));*/
lua_call(L, 1, LUA_MULTRET);//{table},traceback(), callb(), args...
- printf("bar\n");
- printf("Top: %d\n",lua_gettop(L));
+ /*printf("bar\n");*/
+ /*printf("Top: %d\n",lua_gettop(L));*/
for(int i = 1; i <= lua_gettop(L); i++){
- printf("-%d - %s\n",i,lua_typename(L,lua_type(L,-i)));
+ /*printf("-%d - %s\n",i,lua_typename(L,lua_type(L,-i)));*/
}
int numargs = lua_gettop(L) - 3;
- printf("Nargs:%d\n",numargs);
+ /*printf("Nargs:%d\n",numargs);*/
lua_pcall(L, numargs, 0, 2);//{table},traceback()
- printf("Finished with everything, poping last 2 and returning\n");
+ /*printf("Finished with everything, poping last 2 and returning\n");*/
lua_pop(L,2);//
}
@@ -77,7 +77,7 @@ int lnng_aio_alloc(lua_State *L){ int argc = lua_gettop(L);//callback(), args...
lua_createtable(L,argc - 1, 0);//callback(), args..., {}
for(int i = 1; i < argc; i++){
- printf("Adding element %d to arg table (%s)\n",i,lua_typename(L,lua_type(L,i + 1)));
+ /*printf("Adding element %d to arg table (%s)\n",i,lua_typename(L,lua_type(L,i + 1)));*/
lua_pushnumber(L, i);
lua_getglobal(L,"print");
lua_pushvalue(L, i + 1);
@@ -97,7 +97,7 @@ int lnng_aio_alloc(lua_State *L){ int err = nng_aio_alloc(&aio, lcallback, (void*)lfaa);
lfaa->aio = aio;
if(err == 0){
- printf("After aio_alloc we have:%d",lua_gettop(L));
+ /*printf("After aio_alloc we have:%d",lua_gettop(L));*/
luaL_setmetatable(L,"nng.aio.struct");
return 1;
}else{
@@ -114,13 +114,13 @@ struct nng_aio* toaio(lua_State *L, int index){ //sleep(duration, aio)
int lnng_aio_sleep(lua_State *L){
- printf("sleep called\n");
+ /*printf("sleep called\n");*/
int duration = luaL_checkinteger(L,1);
- printf("Duration was %d\n");
+ /*printf("Duration was %d\n");*/
nng_aio *aio = toaio(L,2);
- printf("Got aio: %p\n",aio);
+ /*printf("Got aio: %p\n",aio);*/
nng_sleep_aio(duration, aio);
- printf("did sleep\n");
+ /*printf("did sleep\n");*/
return 0;
}
@@ -135,15 +135,15 @@ struct callback_info { };
void push_callback(void *v){
- printf("aio callback received!\n");
+ /*printf("aio callback received!\n");*/
struct callback_info *ci = (struct callback_info*)v;
lua_State *L = ci->L;
- printf("About to lock lua state in callback\n");
+ /*printf("About to lock lua state in callback\n");*/
nng_mtx_lock(ci->lmutex);//lock the lua state
- printf("Done locking lua state in callback\n");
+ /*printf("Done locking lua state in callback\n");*/
int err = nng_aio_result(ci->aio);
if(err != 0){
- printf("This callback was canceled or timed out: %d: %s\n", err, nng_strerror(err));
+ /*printf("This callback was canceled or timed out: %d: %s\n", err, nng_strerror(err));*/
nng_mtx_unlock(ci->lmutex);
return;
}
@@ -156,15 +156,15 @@ void push_callback(void *v){ nng_msg_free(msg);
ci->completed = 1;
lua_settable(L,1);
- printf("About to unlock lua state in callback\n");
+ /*printf("About to unlock lua state in callback\n");*/
nng_mtx_unlock(ci->lmutex);
- printf("About to lock condition mutex in callback\n");
+ /*printf("About to lock condition mutex in callback\n");*/
nng_mtx_lock(ci->cmutex);
- printf("About wake condition\n");
+ /*printf("About wake condition\n");*/
nng_cv_wake(ci->cv);
- printf("Done wake condition\n");
+ /*printf("Done wake condition\n");*/
nng_mtx_unlock(ci->cmutex);
- printf("Done with callback\n");
+ /*printf("Done with callback\n");*/
}
//TODO: there is a wierd bug here:
@@ -177,45 +177,45 @@ int lnng_aio_recv(lua_State *L){ err |= nng_mtx_alloc(&callbackmtx);
err |= nng_mtx_alloc(&setupmtx);
if(err != 0){
- printf("Something when wrong when allocating mutexes\n");
+ /*printf("Something when wrong when allocating mutexes\n");*/
lua_pushboolean(L,0);
lua_pushstring(L,nng_strerror(err));
return 2;
}
int argv = lua_gettop(L);
- printf("Receiving any on %d sockets\n",argv);
+ /*printf("Receiving any on %d sockets\n",argv);*/
struct callback_info **cis = (struct callback_info**)malloc(sizeof(struct callback_info*) * argv);
nng_mtx_lock(luamtx);
- printf("Locked lua state\n");
+ /*printf("Locked lua state\n");*/
nng_cv *cv;
nng_cv_alloc(&cv, callbackmtx);
/*nng_mtx_lock(callbackmtx);//wait for one of the callbacks to happen*/
- printf("Callback 1 happened\n");
+ /*printf("Callback 1 happened\n");*/
for(int i = 0; i < argv; i++){
- printf("\tSetting up async %d\n", i);
+ /*printf("\tSetting up async %d\n", i);*/
nng_socket *sock = tosocket(L,-1);
int sref = luaL_ref(L,LUA_REGISTRYINDEX);
- printf("\tGot socket ref %d\n", sref);
+ /*printf("\tGot socket ref %d\n", sref);*/
cis[i] = (struct callback_info*)malloc(sizeof(struct callback_info));
struct callback_info *ci = cis[i];
- printf("\tLooking at ci %p\n",ci);
+ /*printf("\tLooking at ci %p\n",ci);*/
ci->L = L;
ci->lmutex = luamtx;
ci->cmutex = callbackmtx;
ci->socketref = sref;
ci->completed = 0;
ci->cv = cv;
- printf("\tAbout to alloc aio\n");
+ /*printf("\tAbout to alloc aio\n");*/
nng_aio_alloc(&(ci->aio), push_callback, ci);
- printf("\tAllocated aio\n");
- printf("\tEverything else set on callback info\n");
+ /*printf("\tAllocated aio\n");*/
+ /*printf("\tEverything else set on callback info\n");*/
nng_recv_aio(*sock, ci->aio);
- printf("\tSet up async receive %d\n",i);
+ /*printf("\tSet up async receive %d\n",i);*/
}
lua_newtable(L);//table that will hold [socket] = message
- printf("About to unlock lua state\n");
+ /*printf("About to unlock lua state\n");*/
nng_mtx_unlock(luamtx);
- printf("Unlocked lua state\n");
+ /*printf("Unlocked lua state\n");*/
/*nng_mtx_lock(callbackmtx);//was unlocked by the callback, luamtx is locked at this point*/
int complete = 0;
nng_mtx_lock(callbackmtx);
@@ -223,30 +223,30 @@ int lnng_aio_recv(lua_State *L){ for(int i = 0; i < argv; i++){
struct callback_info *ci = cis[i];
if(ci->completed > 0){
- printf("At least 1 completed! breaking!\n");
+ /*printf("At least 1 completed! breaking!\n");*/
complete = 1;
goto found;
}
}
- printf("About to wait\n");
+ /*printf("About to wait\n");*/
nng_cv_wait(cv);
- printf("Done waiting, complete is: %d\n", complete);
+ /*printf("Done waiting, complete is: %d\n", complete);*/
}
found:
- printf("Callback 2 happened\n");
+ /*printf("Callback 2 happened\n");*/
nng_mtx_unlock(callbackmtx);
- printf("Callback done\n");
+ /*printf("Callback done\n");*/
for(int i = 0; i < argv; i++){
struct callback_info *ci = cis[i];
- printf("About to stop aio %d\n",ci->aio);
+ /*printf("About to stop aio %d\n",ci->aio);*/
/*nng_aio_cancel(ci->aio);*/
nng_aio_stop(ci->aio);
nng_aio_free(ci->aio);
free(ci);
- printf("Stopped aio %d\n",ci->aio);
+ /*printf("Stopped aio %d\n",ci->aio);*/
}
free(cis);
- printf("Freeing things\n");
+ /*printf("Freeing things\n");*/
nng_cv_free(cv);
nng_mtx_free(callbackmtx);
nng_mtx_unlock(luamtx);//mutexes must not be locked when they are freed
diff --git a/src/lua-nng.c b/src/lua-nng.c index 9d12f30..68ea659 100644 --- a/src/lua-nng.c +++ b/src/lua-nng.c @@ -76,6 +76,12 @@ nng_dialer* todialer(lua_State *L, int offset){ return (nng_dialer*)lua_touserdata(L,offset);
}
+nng_sockaddr* tosockaddr(lua_State *L, int offset){
+ luaL_checkudata(L,offset,"nng.sockaddr");
+ return (nng_sockaddr*)lua_touserdata(L,offset);
+}
+
+
//socket:listen(url[, flags]) :: listener
int lnng_listen(lua_State *L){
int argc = lua_gettop(L);
@@ -259,6 +265,68 @@ int lnng_listener_set(lua_State *L){ return 0;
}
+int lnng_sockaddr_get(lua_State *L){
+ nng_sockaddr *sa = tosockaddr(L,1);
+ unsigned int f = sa->s_family;
+ const char *field = luaL_checkstring(L,2);
+ lua_pop(L,2);
+ printf("Getting %s from sockaddr\n",field);
+ if(strcmp(field,"type") == 0){
+ lua_pushnumber(L,f);
+ return 1;
+ }
+ if(f == NNG_AF_UNSPEC){
+ printf("Unspec\n");
+ lua_pushnil(L);
+ return 1;
+ }else if(f == NNG_AF_INPROC){
+ printf("Inproc\n");
+ nng_sockaddr_inproc sai = sa->s_inproc;
+ if(strcmp(field,"name") == 0){
+ lua_pushstring(L, sai.sa_name);
+ return 1;
+ }
+ }else if(f == NNG_AF_IPC){
+ printf("IPC\n");
+ nng_sockaddr_ipc sai = sa->s_ipc;
+ if(strcmp(field,"path") == 0){
+ lua_pushstring(L, sai.sa_path);
+ return 1;
+ }
+ }else if(f == NNG_AF_INET){
+ printf("Inet\n");
+ nng_sockaddr_in sai = sa->s_in;
+ if(strcmp(field,"addr") == 0){
+ lua_pushnumber(L, sai.sa_addr);
+ return 1;
+ }else if(strcmp(field,"port") == 0){
+ lua_pushnumber(L, sai.sa_port);
+ return 1;
+ }
+ }else if(f == NNG_AF_INET6){
+ nng_sockaddr_in6 sai = sa->s_in6;
+ if(strcmp(field,"addr") == 0){
+ lua_pushlstring(L,sai.sa_addr,16);
+ return 1;
+ }else if(strcmp(field,"port") == 0){
+ lua_pushnumber(L,sai.sa_port);
+ return 1;
+ }
+ }else if(f == NNG_AF_ZT){
+ nng_sockaddr_zt sai = sa->s_zt;
+ if(strcmp(field,"nwid") == 0){
+ lua_pushnumber(L,sai.sa_nwid);
+ return 1;
+ }else if(strcmp(field,"nodeid") == 0){
+ lua_pushnumber(L,sai.sa_nodeid);
+ return 1;
+ }else if(strcmp(field,"port") == 0){
+ lua_pushnumber(L,sai.sa_port);
+ return 1;
+ }
+ }
+}
+
//set(socket, "flag", value)
int lnng_socket_set(lua_State *L){
nng_socket *sock = tosocket(L,1);
@@ -315,23 +383,34 @@ int lnng_socket_set(lua_State *L){ //get(socket,"flag",value)
int lnng_socket_get(lua_State *L){
+ /*printf("Lua stack is %d\n",lua_gettop(L));*/
nng_socket *sock = tosocket(L,1);
const char *flag = luaL_checkstring(L,2);
- //TODO NNG_OPT_LOCADDR //read-only
+ //NNG_OPT_LOCADDR - listeners, dialers, and connected pipes
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RAW, bool, nng_socket_get_bool, lua_pushboolean); //read-only
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECONNMINT, nng_duration, nng_socket_get_ms, lua_pushinteger);
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECONNMAXT, nng_duration, nng_socket_get_ms, lua_pushinteger);
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVBUF, int, nng_socket_get_int, lua_pushinteger);
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVFD, int, nng_socket_get_int, lua_pushinteger); //read-only
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVMAXSZ, size_t, nng_socket_get_size, lua_pushinteger);
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVTIMEO, nng_duration, nng_socket_get_ms, lua_pushinteger);
- //TODO NNG_OPT_REMADDR
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECONNMINT, nng_duration, nng_socket_get_ms, lua_pushinteger);//sockets and dialers, if both dialer and socket are set, dialer overrides socket
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECONNMAXT, nng_duration, nng_socket_get_ms, lua_pushinteger); //sockets and dialers, if both dialer and socket are set, dialer overrides socket
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVBUF, int, nng_socket_get_int, lua_pushinteger);//socket only
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVFD, int, nng_socket_get_int, lua_pushinteger); //socket only, read-only
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVMAXSZ, size_t, nng_socket_get_size, lua_pushinteger);//sockets, dialers and listeners
+ SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_RECVTIMEO, nng_duration, nng_socket_get_ms, lua_pushinteger);//socket only
+ if(strcmp(flag, NNG_OPT_REMADDR) == 0){
+ lua_pop(L,lua_gettop(L));
+ nng_sockaddr *sa = (nng_sockaddr*)lua_newuserdata(L,sizeof(nng_sockaddr));//{udata}
+ int err = nng_socket_get_addr(*sock, NNG_OPT_REMADDR, sa);//{udata}
+ if(err == 0){
+ luaL_setmetatable(L,"nng.sockaddr");
+ return 1;
+ }else{
+ return luaL_error(L,"Failed to lookup local address - %s",nng_strerror(err));
+ }
+ }
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_SENDBUF, int, nng_socket_get_int, lua_pushinteger);
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_SENDFD, int, nng_socket_get_int, lua_pushinteger); //read-only
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_SENDTIMEO, nng_duration, nng_socket_get_ms, lua_pushinteger);
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_SOCKNAME, char*, nng_socket_get_string, lua_pushstring);
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_MAXTTL, int, nng_socket_get_int, lua_pushinteger);
- SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_URL, char*, nng_socket_get_string, lua_pushstring); //read-only
+ //SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_URL, char*, nng_socket_get_string, lua_pushstring); //read-only for dialers, listeners, and pipes
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_PROTO, int, nng_socket_get_int, lua_pushinteger); //read-only
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_PEER, int, nng_socket_get_int, lua_pushinteger); //read-only
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_PROTONAME, char*, nng_socket_get_string, lua_pushstring); //read-only
@@ -366,6 +445,93 @@ int lnng_socket_get(lua_State *L){ //Survayor/respondent options
SOCKET_OPTION_GET(L, sock, flag, NNG_OPT_SURVEYOR_SURVEYTIME, nng_duration, nng_socket_get_ms, lua_pushinteger);
+ lua_pop(L,2);
+
+ //If none of the above options matched, get the value from the metatable
+ int type = luaL_getmetatable(L,"nng.socket_m");////{socket_m}
+ /*luaL_newlib(L,nng_socket_m);*/
+ lua_getfield(L,-1,"__index");
+ lua_getfield(L,-1,flag);//{socket_m},{socket},any
+ int ref = luaL_ref(L,LUA_REGISTRYINDEX);//{socket_m},{socket}
+ lua_pop(L,2);//
+ lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//any
+ return 1;
+}
+
+/*#define DIALER_OPTION_SET(L, socket, flag, matches, ntype, gets, sets) \*/
+ /*if(strcmp(flag, matches) == 0){\*/
+ /*ntype value = (ntype)gets(L,3);\*/
+ /*int err = sets(*socket, flag, value);\*/
+ /*lua_pop(L,lua_gettop(L));\*/
+ /*if(err != 0){\*/
+ /*lua_pushboolean(L,0);\*/
+ /*lua_pushfstring(L,nng_strerror(err));\*/
+ /*return 2;\*/
+ /*}else{\*/
+ /*return 0;\*/
+ /*}\*/
+ /*}*/
+
+/*#define DIALER_OPTION_GET(L, dialer, flag, matches, ntype, gets, pushes) \*/
+ /*if(strcmp(flag, matches) == 0){\*/
+ /*ntype value;\*/
+ /*int err = gets(*socket, flag, &value);\*/
+ /*lua_pop(L,lua_gettop(L));\*/
+ /*if(err != 0){\*/
+ /*lua_pushboolean(L,0);\*/
+ /*lua_pushfstring(L,nng_strerror(err));\*/
+ /*return 2;\*/
+ /*}else{\*/
+ /*pushes(L,value);\*/
+ /*return 1;\*/
+ /*}\*/
+ /*}*/
+
+
+int lnng_dialer_get(lua_State *L){
+ nng_dialer *dialer = todialer(L,1);
+ const char *flag = luaL_checkstring(L,2);
+ if(strcmp(flag, NNG_OPT_LOCADDR) == 0){
+ printf("Looking for dialer's locaddr\n");
+ lua_pop(L,lua_gettop(L));
+ nng_sockaddr *sa = (nng_sockaddr*)lua_newuserdata(L,sizeof(nng_sockaddr));//{udata}
+ int err = nng_dialer_get_addr(*dialer , NNG_OPT_LOCADDR, sa);//{udata}
+ if(err == 0){
+ luaL_setmetatable(L,"nng.sockaddr");
+ return 1;
+ }else{
+ return luaL_error(L,"Failed to lookup local address - %s",nng_strerror(err));
+ }
+ }
+ SOCKET_OPTION_GET(L, dialer, flag, NNG_OPT_RECONNMINT, nng_duration, nng_dialer_get_ms, lua_pushinteger);//sockets and dialers, if both dialer and socket are set, dialer overrides socket
+ SOCKET_OPTION_GET(L, dialer, flag, NNG_OPT_RECONNMAXT, nng_duration, nng_dialer_get_ms, lua_pushinteger); //sockets and dialers, if both dialer and socket are set, dialer overrides socket
+ SOCKET_OPTION_GET(L, dialer, flag, NNG_OPT_RECVMAXSZ, size_t, nng_dialer_get_size, lua_pushinteger);//sockets, dialers and listeners
+ if(strcmp(flag, NNG_OPT_REMADDR) == 0){
+ lua_pop(L,lua_gettop(L));
+ nng_sockaddr *sa = (nng_sockaddr*)lua_newuserdata(L,sizeof(nng_sockaddr));//{udata}
+ int err = nng_dialer_get_addr(*dialer, NNG_OPT_REMADDR, sa);//{udata}
+ if(err == 0){
+ luaL_setmetatable(L,"nng.sockaddr");
+ return 1;
+ }else{
+ return luaL_error(L,"Failed to lookup remote address - %s",nng_strerror(err));
+ }
+ }
+ SOCKET_OPTION_GET(L, dialer, flag, NNG_OPT_URL, char*, nng_dialer_get_string, lua_pushstring); //read-only for dialers, listeners, and pipes
+
+ //If none of the above options matched, get the value from the metatable
+ int type = luaL_getmetatable(L,"nng.dialer_m");////{socket_m}
+ /*luaL_newlib(L,nng_socket_m);*/
+ lua_getfield(L,-1,"__index");
+ lua_getfield(L,-1,flag);//{socket_m},{socket},any
+ int ref = luaL_ref(L,LUA_REGISTRYINDEX);//{socket_m},{socket}
+ lua_pop(L,2);//
+ lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//any
+ return 1;
+}
+
+int lnng_dialer_set(lua_State *L){
+
}
static const struct luaL_Reg nng_dialer_m[] = {
@@ -378,12 +544,6 @@ static const struct luaL_Reg nng_listener_m[] = { {NULL, NULL}
};
-static const struct luaL_Reg nng_socket_sub_m[] = {
- {"subscribe", lnng_subscribe},
- {"unsubscribe", lnng_unsubscribe},
- {NULL, NULL}
-};
-
static const struct luaL_Reg nng_socket_m[] = {
{"dial", lnng_dial},
{"listen", lnng_listen},
@@ -416,20 +576,27 @@ static const struct luaL_Reg nng_f[] = { #define flag(name) lua_pushnumber(L,name); lua_setfield(L,-2,#name);
#define option(name) lua_pushstring(L,name); lua_setfield(L,-2,#name);
int luaopen_nng(lua_State *L){
+ luaL_newmetatable(L,"nng.socket_m");//{}
+ luaL_newlib(L,nng_socket_m);//{},{socket_m}
+ lua_setfield(L,-2,"__index");//{__index={socket_m}}
+ lua_pop(L,1);//
+
luaL_newmetatable(L,"nng.socket");//{}
- luaL_newlib(L,nng_socket_m);//{},{}
- lua_newtable(L);//{},{},{}
- lua_pushcfunction(L,lnng_socket_get);//{},{},{},get()
- lua_setfield(L,-2,"__index");//{},{},{__index=get()}
- lua_setmetatable(L,-2);//{},{}
- lua_setfield(L,-2,"__index");//{__index = {}}
- lua_pushcfunction(L,lnng_socket_close);//{__index = {}},close()
- lua_setfield(L,-2,"__gc");//{__index = {}, __gc = close()}
- lua_pushcfunction(L,lnng_socket_set);//{__index = {}, __gc = close()}, set()
- lua_setfield(L,-2,"__newindex");//{__index = {}, __gc = close(), __newindex = set()}
+ lua_pushcfunction(L,lnng_socket_get);//{},socket_get()
+ lua_setfield(L,-2,"__index");//{__index = socket_get()}
+ lua_pushcfunction(L,lnng_socket_close);//{__index = {socket_m}},close()
+ lua_setfield(L,-2,"__gc");//{__index = {socket_m}, __gc = close()}
+ lua_pushcfunction(L,lnng_socket_set);//{__index = {socket_m}, __gc = close()}, set()
+ lua_setfield(L,-2,"__newindex");//{__index = {socket_m}, __gc = close(), __newindex = set()}
lua_pop(L,1);
- luaL_newmetatable(L,"nng.dialer");
+ luaL_newmetatable(L,"nng.dialer");//{}
+ lua_pushcfunction(L,lnng_dialer_get);//{},dialer_get()
+ lua_setfield(L,-2,"__index");
+ lua_pushcfunction(L,lnng_dialer_set);
+ lua_setfield(L,-2,"__newindex");
+
+ luaL_newmetatable(L,"nng.dialer_m");
luaL_newlib(L,nng_dialer_m);
lua_setfield(L,-2,"__index");
/*lua_pushcfunction(L,lnng_dialer_close);*/
@@ -443,6 +610,11 @@ int luaopen_nng(lua_State *L){ /*lua_setfield(L,-2,"__gc");*/
lua_pop(L,1);
+ luaL_newmetatable(L,"nng.sockaddr");//{nng.sockaddr}
+ lua_pushcfunction(L,lnng_sockaddr_get);//{nng.sockaddr},sockaddr_get
+ lua_setfield(L,-2,"__index");//{nng_sockaddr}
+ lua_pop(L,1);
+
luaL_newlib(L,nng_f);
luaopen_nng_aio(L);
lua_setfield(L,-2,"aio");
|
