diff options
| author | Alex Pickering <alex@cogarr.net> | 2021-09-12 16:58:26 -0500 |
|---|---|---|
| committer | Alex Pickering <alex@cogarr.net> | 2021-09-12 16:58:26 -0500 |
| commit | 346304da786a652f25f73ee80957ec6fd16716c8 (patch) | |
| tree | 682717483aa24b6119d82856d48038345f44f7aa | |
| parent | 835cda73fe2cf1d8c99d7599e9bfb92cd70444e9 (diff) | |
| download | lua-nng-346304da786a652f25f73ee80957ec6fd16716c8.tar.gz lua-nng-346304da786a652f25f73ee80957ec6fd16716c8.tar.bz2 lua-nng-346304da786a652f25f73ee80957ec6fd16716c8.zip | |
Line endings to unix
Convert all line endings to unix line endings.
| -rw-r--r-- | README.md | 71 | ||||
| -rw-r--r-- | src/lua-nng-aio.h | 2 | ||||
| -rw-r--r-- | src/lua-nng-common.h | 22 | ||||
| -rw-r--r-- | src/lua-nng-http.c | 106 | ||||
| -rw-r--r-- | src/lua-nng.c | 12 | ||||
| -rw-r--r-- | src/lua-nng.h | 52 |
6 files changed, 150 insertions, 115 deletions
@@ -1,27 +1,44 @@ -# lua-nng
-
-This is a simple binding of [Nanomessage Next Generation](https://github.com/nanomsg/nng) to lua.
-
-## Installation
-
-The easiest way to download lua-nng is with [luarocks](https://github.com/luarocks/luarocks).
-
-```
-luarocks install --server=http://rocks.cogarr.net lua-nng
-```
-
-## Example
-
- local nng = require("nng")
-
- local s1 = nng.pair1_open()
- local s2 = nng.pair1_open()
-
- s1:listen("ipc:///tmp/pair.ipc")
- s2:dial("ipc:///tmp/pair.ipc")
-
- s2:send("hello")
- print(s1:recv()) --prints "hello"
-
-For more examples, see spec/start\_spec.lua
-
+# lua-nng + +This is a simple binding of [Nanomessage Next Generation](https://github.com/nanomsg/nng) to lua. + +## Installation + +First you'll need a copy of [nng](https://github.com/nanomsg/nng) + + git clone https://github.com/nanomsg/nng + cd nng + mkdir build + cd build + cmake .. -DBUILD_SHARED_LIBS=True + make && sudo make install + + +The easiest way to download lua-nng is with [luarocks](https://github.com/luarocks/luarocks). + +You can also clone this repository and build locally + + git clone https://cogarr.net/source/cgit.cgi/lua-nng + cd lua-nng + sudo luarocks build + + +``` +luarocks install --server=http://rocks.cogarr.net lua-nng +``` + +## Example + + local nng = require("nng") + + local s1 = nng.pair1_open() + local s2 = nng.pair1_open() + + s1:listen("ipc:///tmp/pair.ipc") + s2:dial("ipc:///tmp/pair.ipc") + + s2:send("hello") + print(s1:recv()) --prints "hello" + +For more examples, see spec/start\_spec.lua + diff --git a/src/lua-nng-aio.h b/src/lua-nng-aio.h index da5e367..ea4c803 100644 --- a/src/lua-nng-aio.h +++ b/src/lua-nng-aio.h @@ -1 +1 @@ -int luaopen_nng_aio(lua_State *L);
+int luaopen_nng_aio(lua_State *L); diff --git a/src/lua-nng-common.h b/src/lua-nng-common.h index a56dd8a..ffdc4c7 100644 --- a/src/lua-nng-common.h +++ b/src/lua-nng-common.h @@ -1,6 +1,16 @@ -#include <lua.h>
-#include <lualib.h>
-#include <lauxlib.h>
-
-// lua runtime's traceback function
-int traceback (lua_State *L);
+#include <lua.h> +#include <lualib.h> +#include <lauxlib.h> + +/* +Lua version independence 5.1+ +*/ +#ifndef luaL_newlib + #define luaL_newlib(l,r) luaL_register(l,NULL,r) +#endif +#ifndef luaL_setmetatable + #define luaL_setmetatable(l,s) luaL_getmetatable(l,s); lua_setmetatable(l,-2); +#endif + +// lua runtime's traceback function +int traceback (lua_State *L); diff --git a/src/lua-nng-http.c b/src/lua-nng-http.c index 61f7401..c3bc89f 100644 --- a/src/lua-nng-http.c +++ b/src/lua-nng-http.c @@ -1,52 +1,54 @@ -#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
-
-#define NNG_STATIC_LIB
-
-#include <nng/nng.h>
-
-#include <nng/transport/inproc/inproc.h>
-#include <nng/transport/ipc/ipc.h>
-#include <nng/transport/tcp/tcp.h>
-#include <nng/transport/tls/tls.h>
-#include <nng/transport/zerotier/zerotier.h>
-
-#include <nng/protocol/pair1/pair.h>
-#include <nng/protocol/bus0/bus.h>
-#include <nng/protocol/pubsub0/pub.h>
-#include <nng/protocol/pubsub0/sub.h>
-#include <nng/protocol/pipeline0/pull.h>
-#include <nng/protocol/pipeline0/push.h>
-#include <nng/protocol/reqrep0/req.h>
-#include <nng/protocol/reqrep0/rep.h>
-#include <nng/protocol/survey0/respond.h>
-#include <nng/protocol/survey0/survey.h>
-
-void handle_callback(nng_aio *aio){
-
-}
-
-//handler_alloc(string path,function callback) :: http_handler
-int lnng_http_handler_alloc(lua_State *L){
-
-}
-
-static const struct luaL_Reg nng_http_handler_m[] = {
- {NULL, NULL}
-};
-
-static const struct luaL_Reg nng_http_f[] = {
- {"handler_alloc",lnng_http_handler_alloc},
- {NULL, NULL}
-};
-
-int luaopen_nng_http(lua_State *L){
- luaL_newmetatable(L,"nng.http.handler");
- luaL_newlib(L,nng_http_handler_m);
- lua_setfield(L,-2,"__index");
- lua_pop(L,1);
-
- luaL_newlib(L,nng_http_f);
- return 1;
-}
+#include <lua.h> +#include <lauxlib.h> +#include <lualib.h> + +#define NNG_STATIC_LIB + +#include <nng/nng.h> + +#include <nng/transport/inproc/inproc.h> +#include <nng/transport/ipc/ipc.h> +#include <nng/transport/tcp/tcp.h> +#include <nng/transport/tls/tls.h> +#include <nng/transport/zerotier/zerotier.h> + +#include <nng/protocol/pair1/pair.h> +#include <nng/protocol/bus0/bus.h> +#include <nng/protocol/pubsub0/pub.h> +#include <nng/protocol/pubsub0/sub.h> +#include <nng/protocol/pipeline0/pull.h> +#include <nng/protocol/pipeline0/push.h> +#include <nng/protocol/reqrep0/req.h> +#include <nng/protocol/reqrep0/rep.h> +#include <nng/protocol/survey0/respond.h> +#include <nng/protocol/survey0/survey.h> + +#include "lua-nng-common.h" + +void handle_callback(nng_aio *aio){ + +} + +//handler_alloc(string path,function callback) :: http_handler +int lnng_http_handler_alloc(lua_State *L){ + +} + +static const struct luaL_Reg nng_http_handler_m[] = { + {NULL, NULL} +}; + +static const struct luaL_Reg nng_http_f[] = { + {"handler_alloc",lnng_http_handler_alloc}, + {NULL, NULL} +}; + +int luaopen_nng_http(lua_State *L){ + luaL_newmetatable(L,"nng.http.handler"); + luaL_newlib(L,nng_http_handler_m); + lua_setfield(L,-2,"__index"); + lua_pop(L,1); + + luaL_newlib(L,nng_http_f); + return 1; +} diff --git a/src/lua-nng.c b/src/lua-nng.c index 649a022..230c6fb 100644 --- a/src/lua-nng.c +++ b/src/lua-nng.c @@ -27,11 +27,17 @@ #include <string.h> #include "lua-nng-aio.h" +#include "lua-nng-common.h" + +/*#ifndef luaL_setmetatable*/ + /*#define luaL_setmetatable lua_setmetatable*/ +/*#endif*/ + + /*** The lua binding of Nanomessage Next Generation @namespace nng */ -@namespace nng #define OPEN(name)\ int lnng_ ## name ## _open(lua_State *L){\ nng_socket *s = (nng_socket*)lua_newuserdata(L,sizeof(nng_socket));\ @@ -462,7 +468,7 @@ int lnng_socket_get(lua_State *L){ 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_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 @@ -534,7 +540,7 @@ int lnng_dialer_get(lua_State *L){ 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_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 diff --git a/src/lua-nng.h b/src/lua-nng.h index 80b716d..ef96823 100644 --- a/src/lua-nng.h +++ b/src/lua-nng.h @@ -1,26 +1,26 @@ -#define NNG_STATIC_LIB
-
-#include <nng/nng.h>
-
-#include <nng/transport/inproc/inproc.h>
-#include <nng/transport/ipc/ipc.h>
-#include <nng/transport/tcp/tcp.h>
-#include <nng/transport/tls/tls.h>
-#include <nng/transport/zerotier/zerotier.h>
-
-#include <nng/protocol/pair1/pair.h>
-#include <nng/protocol/bus0/bus.h>
-#include <nng/protocol/pubsub0/pub.h>
-#include <nng/protocol/pubsub0/sub.h>
-#include <nng/protocol/pipeline0/pull.h>
-#include <nng/protocol/pipeline0/push.h>
-#include <nng/protocol/reqrep0/req.h>
-#include <nng/protocol/reqrep0/rep.h>
-#include <nng/protocol/survey0/respond.h>
-#include <nng/protocol/survey0/survey.h>
-
-#include <nng/supplemental/util/platform.h>
-
-nng_socket* tosocket(lua_State *L, int offset);
-nng_listener* tolistener(lua_State *L, int offset);
-nng_dialer* todialer(lua_State *L, int offset);
+#define NNG_STATIC_LIB + +#include <nng/nng.h> + +#include <nng/transport/inproc/inproc.h> +#include <nng/transport/ipc/ipc.h> +#include <nng/transport/tcp/tcp.h> +#include <nng/transport/tls/tls.h> +#include <nng/transport/zerotier/zerotier.h> + +#include <nng/protocol/pair1/pair.h> +#include <nng/protocol/bus0/bus.h> +#include <nng/protocol/pubsub0/pub.h> +#include <nng/protocol/pubsub0/sub.h> +#include <nng/protocol/pipeline0/pull.h> +#include <nng/protocol/pipeline0/push.h> +#include <nng/protocol/reqrep0/req.h> +#include <nng/protocol/reqrep0/rep.h> +#include <nng/protocol/survey0/respond.h> +#include <nng/protocol/survey0/survey.h> + +#include <nng/supplemental/util/platform.h> + +nng_socket* tosocket(lua_State *L, int offset); +nng_listener* tolistener(lua_State *L, int offset); +nng_dialer* todialer(lua_State *L, int offset); |
