diff options
author | chai <chaifix@163.com> | 2018-08-14 16:14:32 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-14 16:14:32 +0800 |
commit | 57efa331c7ddc247c9b14dc19d4d98afbeb4e3b4 (patch) | |
tree | 1ebba4cd5b97a771d2f35e708ceda7193b904516 /src/lua/net/luaopen_net.cpp | |
parent | 0d26ed3a45f53fdbd7731b5f2a4d88edef201e44 (diff) |
*update
Diffstat (limited to 'src/lua/net/luaopen_net.cpp')
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp index 13d24dd..7ec9cc7 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/net/luaopen_net.cpp @@ -19,33 +19,35 @@ namespace lua // jin.net.Socket() static int l_Socket(lua_State* L) { - const char* socketType = luax_checkstring(L, 1); SocketInformation info = { 0 }; - 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; + 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); + } } - // 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); - } - Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); Socket* socket = new Socket(info); + Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); proxy->bind(socket, JIN_NETWORK_SOCKET); return 1; } |