aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/net/je_lua_socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/net/je_lua_socket.cpp')
-rw-r--r--src/lua/modules/net/je_lua_socket.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp
index a51f5f3..309f92e 100644
--- a/src/lua/modules/net/je_lua_socket.cpp
+++ b/src/lua/modules/net/je_lua_socket.cpp
@@ -1,5 +1,5 @@
#include "lua/modules/luax.h"
-#include "lua/modules/types.h"
+
#include "lua/common/je_lua_common.h"
#include "libjin/jin.h"
#include "je_lua_buffer.h"
@@ -12,19 +12,21 @@ namespace JinEngine
namespace Lua
{
+ const char* Jin_Lua_Socket = "Socket";
+
typedef Shared<Socket>& SharedSocket;
const int BUFFER_SIZE = 1024;
LUA_IMPLEMENT inline SharedSocket checkSocket(lua_State* L, int pos = 1)
{
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_SOCKET);
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Socket);
return proxy->getShared<Socket>();
}
LUA_IMPLEMENT inline Shared<Buffer>& checkNetBuffer(lua_State* L, int pos = 1)
{
- Proxy* proxy = (Proxy*)luax_checktype(L, pos, JIN_NETWORK_BUFFER);
+ Proxy* proxy = (Proxy*)luax_checktype(L, pos, Jin_Lua_Buffer);
return proxy->getShared<Buffer>();
}
@@ -33,8 +35,8 @@ namespace JinEngine
{
SharedSocket socket = checkSocket(L);
Socket* client = socket->accept();
- Proxy* proxy = luax_newinstance(L, JIN_NETWORK_SOCKET);
- proxy->bind(new Shared<Socket>(client, JIN_NETWORK_SOCKET));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket);
+ proxy->bind(new Shared<Socket>(client, Jin_Lua_Socket));
return 1;
}
@@ -44,9 +46,9 @@ namespace JinEngine
SharedSocket socket = checkSocket(L);
char buffer[BUFFER_SIZE] = {0};
int size = socket->receive(buffer, BUFFER_SIZE);
- Proxy* proxy = luax_newinstance(L, JIN_NETWORK_BUFFER);
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- proxy->bind(new Shared<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
return 1;
}
@@ -59,8 +61,8 @@ namespace JinEngine
char buffer[BUFFER_SIZE];
int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port);
Net::Buffer* netBuffer = new Net::Buffer(buffer, size);
- Proxy* proxy = luax_newinstance(L, JIN_NETWORK_BUFFER);
- proxy->bind(new Shared<Buffer>(netBuffer, JIN_NETWORK_BUFFER));
+ Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer);
+ proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer));
return 1;
}
@@ -102,7 +104,7 @@ namespace JinEngine
LUA_IMPLEMENT int l_gc(lua_State* L)
{
- Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_SOCKET);
+ Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Socket);
proxy->release();
return 0;
}
@@ -120,7 +122,7 @@ namespace JinEngine
{ "configBlocking", l_configBlocking },
{ 0, 0 }
};
- luax_newtype(L, JIN_NETWORK_SOCKET, socket_function);
+ luax_newtype(L, Jin_Lua_Socket, socket_function);
return 0;
}