From 92f23fe1ffe0ce9b9ade92038f7353aece0eef45 Mon Sep 17 00:00:00 2001 From: Syping Date: Fri, 3 Jul 2020 19:24:41 +0200 Subject: [PATCH] add createTcpSocket --- src/luaengineio/luaengine/LuaEngineIO.cpp | 2 +- .../luaengine/LuaEngineNetwork.cpp | 27 +++++++++++++++++++ .../luaengine/LuaEngineNetwork.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/luaengineio/luaengine/LuaEngineIO.cpp b/src/luaengineio/luaengine/LuaEngineIO.cpp index 5910006..434762d 100644 --- a/src/luaengineio/luaengine/LuaEngineIO.cpp +++ b/src/luaengineio/luaengine/LuaEngineIO.cpp @@ -144,7 +144,7 @@ int LuaEngineIO::eIOWrite(lua_State *L_p) void *pointer = getPointer(L_p, 1); if (pointer != NULL) { if (((QObject*)pointer)->inherits("QIODevice")) { - ((QIODevice*)pointer)->write(getVariant(L_p, 2).toByteArray()); + ((QIODevice*)pointer)->write(getVariant(L_p, 2).toString().toUtf8()); } } } diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp index 1f14974..838ec47 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.cpp @@ -18,12 +18,20 @@ #include "LuaEngineNetwork.h" #include #include +#ifdef QT_NO_SSL +#include +#else +#include +#endif void LuaEngineNetwork::pushClass(lua_State *L_p) { // Local Socket pushFunction(L_p, "createLocalSocket", createLocalSocket); + // TCP Socket + pushFunction(L_p, "createTcpSocket", createTcpSocket); + // Socket pushFunction(L_p, "socketConnect", socketConnect); pushFunction(L_p, "socketDisconnect", socketDisconnect); @@ -49,6 +57,25 @@ int LuaEngineNetwork::createLocalSocket(lua_State *L_p) return 1; } +int LuaEngineNetwork::createTcpSocket(lua_State *L_p) +{ + QObject *parent = nullptr; + if (getArgumentCount(L_p) >= 1) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + parent = (QObject*)pointer; + } + } +#ifdef QT_NO_SSL + QTcpSocket *tcpSocket = new QTcpSocket(parent); +#else + QSslSocket *tcpSocket = new QSslSocket(parent); +#endif + tcpSocket->setObjectName(nameForPointer(tcpSocket)); + pushPointer(L_p, tcpSocket); + return 1; +} + int LuaEngineNetwork::socketConnect(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { diff --git a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h index cf18d79..5f61951 100644 --- a/src/luaenginenetwork/luaengine/LuaEngineNetwork.h +++ b/src/luaenginenetwork/luaengine/LuaEngineNetwork.h @@ -29,6 +29,7 @@ public: static void pushClass(lua_State *L_p); static void pushClass(LuaEngine *luaEngine); static int createLocalSocket(lua_State *L_p); + static int createTcpSocket(lua_State *L_p); static int socketConnect(lua_State *L_p); static int socketDisconnect(lua_State *L_p);