diff options
author | chai <chaifix@163.com> | 2018-05-21 16:02:00 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-05-21 16:02:00 +0800 |
commit | fa234f9663b992cf50bcf865a1cde6845b42193c (patch) | |
tree | 34ecd41b60ef48c960a79a4077e5e0c8536102fd /src/lua/net/luaopen_net.cpp | |
parent | 51ba9cb2a6b0b9395a2912eadeb954c95e4c1d3c (diff) |
修改audio模块
Diffstat (limited to 'src/lua/net/luaopen_net.cpp')
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp new file mode 100644 index 0000000..821f273 --- /dev/null +++ b/src/lua/net/luaopen_net.cpp @@ -0,0 +1,110 @@ +/** +* Notice: the net module is not finished yet. +*/ +#include "lua/luax.h" +#include "3rdparty/tekcos/tekcos.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) + { + 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} + }; + + // only tcp + int luaopen_net(lua_State* L) + { + luax_newlib(L, f); + + return 1; + } +} +}
\ No newline at end of file |