add socketDisconnect

This commit is contained in:
Syping 2020-07-03 19:00:45 +02:00
parent 188dd0c9cb
commit 64a3508441
2 changed files with 18 additions and 0 deletions

View file

@ -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;

View file

@ -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;