From 57efa331c7ddc247c9b14dc19d4d98afbeb4e3b4 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 14 Aug 2018 16:14:32 +0800 Subject: *update --- src/lua/net/luaopen_net.cpp | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'src/lua/net/luaopen_net.cpp') 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; } -- cgit v1.1-26-g67d0