diff options
Diffstat (limited to 'src/lua/modules/net')
-rw-r--r-- | src/lua/modules/net/je_lua_buffer.cpp | 11 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_buffer.h | 3 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_net.cpp | 12 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_net.h | 0 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_socket.cpp | 24 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_socket.h | 14 |
6 files changed, 44 insertions, 20 deletions
diff --git a/src/lua/modules/net/je_lua_buffer.cpp b/src/lua/modules/net/je_lua_buffer.cpp index 751de05..2565d60 100644 --- a/src/lua/modules/net/je_lua_buffer.cpp +++ b/src/lua/modules/net/je_lua_buffer.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" @@ -8,11 +8,14 @@ namespace JinEngine { namespace Lua { + + const char* Jin_Lua_Buffer = "Buffer"; + typedef Shared<Net::Buffer>& SharedBuffer; static inline SharedBuffer checkNetBuffer(lua_State* L) { - Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER); + Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer); return proxy->getShared<Net::Buffer>(); } @@ -110,7 +113,7 @@ namespace JinEngine LUA_IMPLEMENT int l_gc(lua_State* L) { - Proxy* proxy = (Proxy*)luax_checktype(L, 1, JIN_NETWORK_BUFFER); + Proxy* proxy = (Proxy*)luax_checktype(L, 1, Jin_Lua_Buffer); proxy->release(); return 0; } @@ -127,7 +130,7 @@ namespace JinEngine { 0, 0 } }; - luax_newtype(L, JIN_NETWORK_BUFFER, netbuffer_function); + luax_newtype(L, Jin_Lua_Buffer, netbuffer_function); return 0; } diff --git a/src/lua/modules/net/je_lua_buffer.h b/src/lua/modules/net/je_lua_buffer.h index d713f53..d24a4e2 100644 --- a/src/lua/modules/net/je_lua_buffer.h +++ b/src/lua/modules/net/je_lua_buffer.h @@ -9,6 +9,9 @@ namespace JinEngine { namespace Lua { + + extern const char* Jin_Lua_Buffer; + namespace Net { diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp index 1d0204a..795eb18 100644 --- a/src/lua/modules/net/je_lua_net.cpp +++ b/src/lua/modules/net/je_lua_net.cpp @@ -1,8 +1,10 @@ #include "lua/modules/luax.h" -#include "lua/modules/types.h" + #include "libjin/jin.h" #include "lua/common/je_lua_common.h" + #include "je_lua_buffer.h" +#include "je_lua_socket.h" namespace JinEngine { @@ -48,17 +50,17 @@ namespace Lua } } Socket* socket = new Socket(info); - Proxy* proxy = luax_newinstance(L, JIN_NETWORK_SOCKET); - proxy->bind(new Shared<Socket>(socket, JIN_NETWORK_SOCKET)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket); + proxy->bind(new Shared<Socket>(socket, Jin_Lua_Socket)); return 1; } LUA_IMPLEMENT int l_Buffer(lua_State* L) { int size = luax_checkinteger(L, 1); - Proxy* proxy = luax_newinstance(L, JIN_NETWORK_BUFFER); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer); Net::Buffer* buffer = new Net::Buffer(size); - proxy->bind(new Shared<Buffer>(buffer, JIN_NETWORK_BUFFER)); + proxy->bind(new Shared<Buffer>(buffer, Jin_Lua_Buffer)); return 1; } diff --git a/src/lua/modules/net/je_lua_net.h b/src/lua/modules/net/je_lua_net.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/lua/modules/net/je_lua_net.h 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; } diff --git a/src/lua/modules/net/je_lua_socket.h b/src/lua/modules/net/je_lua_socket.h new file mode 100644 index 0000000..83c08fb --- /dev/null +++ b/src/lua/modules/net/je_lua_socket.h @@ -0,0 +1,14 @@ +#ifndef __JE_LUA_SOCKET_H__ +#define __JE_LUA_SOCKET_H__ + +namespace JinEngine +{ + namespace Lua + { + + extern const char* Jin_Lua_Socket; + + } +} + +#endif
\ No newline at end of file |