aboutsummaryrefslogtreecommitdiff
path: root/src/lua/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/net')
-rw-r--r--src/lua/net/Socket.h2
-rw-r--r--src/lua/net/luaopen_Buffer.cpp2
-rw-r--r--src/lua/net/luaopen_Socket.cpp2
-rw-r--r--src/lua/net/luaopen_net.cpp48
4 files changed, 28 insertions, 26 deletions
diff --git a/src/lua/net/Socket.h b/src/lua/net/Socket.h
index 5834092..e3ef9c2 100644
--- a/src/lua/net/Socket.h
+++ b/src/lua/net/Socket.h
@@ -16,7 +16,6 @@ namespace net
class Socket : public Object
{
public:
- Socket() {}
Socket(SocketInformation info)
{
@@ -63,6 +62,7 @@ namespace net
private:
jin::net::Socket* socket;
+ Socket() {}
~Socket()
{
delete socket;
diff --git a/src/lua/net/luaopen_Buffer.cpp b/src/lua/net/luaopen_Buffer.cpp
index 0ab47cb..6d42c86 100644
--- a/src/lua/net/luaopen_Buffer.cpp
+++ b/src/lua/net/luaopen_Buffer.cpp
@@ -116,7 +116,7 @@ namespace net
}
static const luaL_Reg netbuffer_function[] = {
- { "__gc", l_gc },
+ { "__gc", l_gc },
{ "append", l_append },
{ "grabString", l_grabString },
{ "grabInteger", l_grabInteger },
diff --git a/src/lua/net/luaopen_Socket.cpp b/src/lua/net/luaopen_Socket.cpp
index abcd8f2..5ccdaa0 100644
--- a/src/lua/net/luaopen_Socket.cpp
+++ b/src/lua/net/luaopen_Socket.cpp
@@ -45,8 +45,8 @@ namespace lua
Socket* socket = checkSocket(L);
char buffer[BUFFER_SIZE] = {0};
int size = socket->receive(buffer, BUFFER_SIZE);
- net::Buffer* netBuffer = new net::Buffer(buffer, size);
Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy));
+ net::Buffer* netBuffer = new net::Buffer(buffer, size);
proxy->bind(netBuffer, JIN_NETWORK_BUFFER);
return 1;
}
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;
}