aboutsummaryrefslogtreecommitdiff
path: root/src/libjin-lua/modules/net/l_net.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-09-13 15:08:43 +0800
committerchai <chaifix@163.com>2019-09-13 15:08:43 +0800
commit20535cb86266d7a4828009f3ddca42e35269b9e2 (patch)
tree796e77e4a34ed52b6c92fb58ec432c69ed4232e1 /src/libjin-lua/modules/net/l_net.cpp
parent695eadc9d2a6d2f499b24ee6858325f6e22da077 (diff)
*格式化代码
Diffstat (limited to 'src/libjin-lua/modules/net/l_net.cpp')
-rw-r--r--src/libjin-lua/modules/net/l_net.cpp128
1 files changed, 64 insertions, 64 deletions
diff --git a/src/libjin-lua/modules/net/l_net.cpp b/src/libjin-lua/modules/net/l_net.cpp
index 5569381..512cf9a 100644
--- a/src/libjin-lua/modules/net/l_net.cpp
+++ b/src/libjin-lua/modules/net/l_net.cpp
@@ -7,73 +7,73 @@
namespace JinEngine
{
- namespace Lua
- {
+ namespace Lua
+ {
- using namespace JinEngine::Lua::Net;
- using namespace JinEngine::Net;
+ using namespace JinEngine::Lua::Net;
+ using namespace JinEngine::Net;
- LUA_IMPLEMENT int l_initNetwork(lua_State* L)
- {
- JinEngine::Net::NetManager::get()->start();
- return 1;
- }
-
- LUA_IMPLEMENT int l_Socket(lua_State* L)
- {
- SocketInformation info = { 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);
- }
- }
- Socket* socket = new Socket(info);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(socket));
- return 1;
- }
+ LUA_IMPLEMENT int l_initNetwork(lua_State* L)
+ {
+ JinEngine::Net::NetManager::get()->start();
+ return 1;
+ }
+
+ LUA_IMPLEMENT int l_Socket(lua_State* L)
+ {
+ SocketInformation info = { 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);
+ }
+ }
+ Socket* socket = new Socket(info);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Socket, new Shared(socket));
+ return 1;
+ }
- LUA_IMPLEMENT int l_Buffer(lua_State* L)
- {
- int size = luax_checkinteger(L, 1);
- Net::Buffer* buffer = new Net::Buffer(size);
- LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(buffer));
- return 1;
- }
+ LUA_IMPLEMENT int l_Buffer(lua_State* L)
+ {
+ int size = luax_checkinteger(L, 1);
+ Net::Buffer* buffer = new Net::Buffer(size);
+ LuaObject* luaObj = luax_newinstance(L, Jin_Lua_Buffer, new Shared(buffer));
+ return 1;
+ }
- LUA_EXPORT int luaopen_net(lua_State* L)
- {
- luaopen_Socket(L);
- luaopen_Buffer(L);
- luaL_Reg methods[] = {
- { "init", l_initNetwork },
- { "newSocket", l_Socket },
- { "newBuffer", l_Buffer },
- { 0, 0 }
- };
- luax_newlib(L, methods);
- return 1;
- }
+ LUA_EXPORT int luaopen_net(lua_State* L)
+ {
+ luaopen_Socket(L);
+ luaopen_Buffer(L);
+ luaL_Reg methods[] = {
+ { "init", l_initNetwork },
+ { "newSocket", l_Socket },
+ { "newBuffer", l_Buffer },
+ { 0, 0 }
+ };
+ luax_newlib(L, methods);
+ return 1;
+ }
- } // namespace Lua
+ } // namespace Lua
} // namespace JinEngine \ No newline at end of file