add createTcpSocket

This commit is contained in:
Syping 2020-07-03 19:24:41 +02:00
parent 9b17fe144d
commit 92f23fe1ff
3 changed files with 29 additions and 1 deletions

View file

@ -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());
}
}
}

View file

@ -18,12 +18,20 @@
#include "LuaEngineNetwork.h"
#include <QAbstractSocket>
#include <QLocalSocket>
#ifdef QT_NO_SSL
#include <QTcpSocket>
#else
#include <QSslSocket>
#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) {

View file

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