diff options
author | chai <chaifix@163.com> | 2018-08-08 21:31:35 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-08 21:31:35 +0800 |
commit | 3a7b295e0fe166d6e4a44cfe17ad8c4f441e6084 (patch) | |
tree | c67c820e51b9ccd19893a590c7aaffcce384d547 /src/lua/net/luaopen_net.cpp | |
parent | aa7549126a4e821cecf75fbc32a433a7f8122d2b (diff) |
*update
Diffstat (limited to 'src/lua/net/luaopen_net.cpp')
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 97 |
1 files changed, 8 insertions, 89 deletions
diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp index 633ccdd..8d67487 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/net/luaopen_net.cpp @@ -1,104 +1,24 @@ -/** -* Notice: the net module is not finished yet. -*/ #include "lua/luax.h" -/* -#include "3rdparty/tekcos/tekcos.h" +#include "libjin/jin.h" namespace jin { namespace lua { - struct - { - tk_TCPsocket* sk; - }context; - - //* A table is needed. For example: - //* local conf = { - //* mode = "server", - //* ip = "", - //* port = 8000 - //* } - - static int l_open(lua_State* L) - { - // init context.sk - context.sk = 0; - if (!luax_istable(L, 1)) - { - luax_typerror(L, 1, "table is needed"); - return 0; - } - luax_getfield(L, 1, "mode"); - if (luax_isnil(L, -1)) - {// no mode field - luax_error(L, "mode field is needed, but get nil"); - return 0; - } - const char* mode = luax_checkstring(L, -1); - if (strcmp(mode, "server") == 0 || strcmp(mode, "client") == 0) - { - - if (strcmp(mode, "server") == 0) - {// a server, ignore ip field - - } - else - { - - } - } - else - { - luax_error(L, "\"server\" or \"client\" is needed, but get %s", mode); - return 0; - } - return 1; - } - - static int l_accept(lua_State* L) - { - return 1; - } - - static int l_send(lua_State* L) - { - return 1; - } - static int l_recv(lua_State* L) - { - return 1; - } - - static int l_close(lua_State* L) - { - return 1; - } - - static int l_nonblocking(lua_State* L) - { - return 1; - } - - // block mode by default - static int l_blocking(lua_State* L) + static int l_initNetwork(lua_State* L) { + jin::net::Net::get()->init(); return 1; } static const luaL_Reg f[] = { - {"open", l_open}, - {"accept", l_accept}, - {"send", l_send}, - {"recv", l_recv}, - {"close", l_close}, - {"blocking", l_blocking }, - {"nonblocking", l_nonblocking}, - {0, 0} + { "init", l_initNetwork}, + { 0, 0 } }; + extern int luaopen_Socket(lua_State* L); + // only tcp int luaopen_net(lua_State* L) { @@ -108,5 +28,4 @@ namespace lua } } -} -*/
\ No newline at end of file +}
\ No newline at end of file |