diff options
author | chai <chaifix@163.com> | 2018-08-22 13:58:13 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-22 13:58:13 +0800 |
commit | 36621e6be9604517c900adc0d97665e975c2b325 (patch) | |
tree | d3db26c2de6b47aee96f6a24d2595ff80a8869b7 /src/lua/modules/net/luaopen_net.cpp | |
parent | 95df5cf921f57bfeac0d819994210dfcc2dcad14 (diff) |
*update
Diffstat (limited to 'src/lua/modules/net/luaopen_net.cpp')
-rw-r--r-- | src/lua/modules/net/luaopen_net.cpp | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/lua/modules/net/luaopen_net.cpp b/src/lua/modules/net/luaopen_net.cpp deleted file mode 100644 index a984920..0000000 --- a/src/lua/modules/net/luaopen_net.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "lua/modules/luax.h" -#include "lua/modules/types.h" -#include "libjin/jin.h" -#include "lua/common/common.h" -#include "Buffer.h" - -namespace jin -{ -namespace lua -{ - using namespace jin::lua::net; - using namespace jin::net; - - static int l_initNetwork(lua_State* L) - { - jin::net::Net::get()->init(); - return 1; - } - - static int l_Socket(lua_State* L) - { - SocketInformation info = { 0 }; - { - const char* socketType = luax_checkstring(L, 1); - if (strcmp(socketType, "TCP") == 0) - info.type = SocketType::TCP; - else if (strcmp(socketType, "UDP") == 0) - info.type = SocketType::UDP; - else - { - luax_error(L, "jin.net.Socket() first paramter wrong, must be TCP or UDP"); - return 0; - } - // type, port - if (luax_gettop(L) == 2) - { - info.port = luax_checkinteger(L, 2); - } - // type, address, port - else if (luax_gettop(L) == 3) - { - if (luax_isstringstrict(L, 2)) - info.address = tk_strtohl(luax_checkstring(L, 2)); - else if (luax_isintegerstrict(L, 2)) - info.address = luax_checkinteger(L, 2); - info.port = luax_checkinteger(L, 3); - } - } - Socket* socket = new Socket(info); - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); - proxy->bind(new Ref<Socket>(socket, JIN_NETWORK_SOCKET)); - return 1; - } - - static int l_Buffer(lua_State* L) - { - int size = luax_checkinteger(L, 1); - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); - net::Buffer* buffer = new net::Buffer(size); - proxy->bind(new Ref<Buffer>(buffer, JIN_NETWORK_BUFFER)); - return 1; - } - - static const luaL_Reg f[] = { - { "init", l_initNetwork }, - { "newSocket", l_Socket }, - { "newBuffer", l_Buffer }, - { 0, 0 } - }; - - extern int luaopen_Socket(lua_State* L); - extern int luaopen_Buffer(lua_State* L); - - int luaopen_net(lua_State* L) - { - luaopen_Socket(L); - luaopen_Buffer(L); - - luax_newlib(L, f); - - return 1; - } - -} // lua -} // jin
\ No newline at end of file |