diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp index 878b7c9..1f14974 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp @@ -26,6 +26,7 @@ void LuaEngineNetwork::pushClass(lua_State *L_p) // Socket pushFunction(L_p, "socketConnect", socketConnect); + pushFunction(L_p, "socketDisconnect", socketDisconnect); } void LuaEngineNetwork::pushClass(LuaEngine *luaEngine) @@ -67,6 +68,22 @@ int LuaEngineNetwork::socketConnect(lua_State *L_p) return 0; } +int LuaEngineNetwork::socketDisconnect(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QLocalSocket")) { + ((QLocalSocket*)pointer)->disconnectFromServer(); + } + else if (((QObject*)pointer)->inherits("QAbstractSocket")) { + ((QAbstractSocket*)pointer)->disconnectFromHost(); + } + } + } + return 0; +} + QString LuaEngineNetwork::nameForPointer(void *pointer) { QString nameStorage; diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h index 3ff154b..cf18d79 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h @@ -30,6 +30,7 @@ public: static void pushClass(LuaEngine *luaEngine); static int createLocalSocket(lua_State *L_p); static int socketConnect(lua_State *L_p); + static int socketDisconnect(lua_State *L_p); private: lua_State *L;