mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +01:00
add createTcpSocket
This commit is contained in:
parent
9b17fe144d
commit
92f23fe1ff
3 changed files with 29 additions and 1 deletions
|
@ -144,7 +144,7 @@ int LuaEngineIO::eIOWrite(lua_State *L_p)
|
||||||
void *pointer = getPointer(L_p, 1);
|
void *pointer = getPointer(L_p, 1);
|
||||||
if (pointer != NULL) {
|
if (pointer != NULL) {
|
||||||
if (((QObject*)pointer)->inherits("QIODevice")) {
|
if (((QObject*)pointer)->inherits("QIODevice")) {
|
||||||
((QIODevice*)pointer)->write(getVariant(L_p, 2).toByteArray());
|
((QIODevice*)pointer)->write(getVariant(L_p, 2).toString().toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,20 @@
|
||||||
#include "LuaEngineNetwork.h"
|
#include "LuaEngineNetwork.h"
|
||||||
#include <QAbstractSocket>
|
#include <QAbstractSocket>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
#ifdef QT_NO_SSL
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#else
|
||||||
|
#include <QSslSocket>
|
||||||
|
#endif
|
||||||
|
|
||||||
void LuaEngineNetwork::pushClass(lua_State *L_p)
|
void LuaEngineNetwork::pushClass(lua_State *L_p)
|
||||||
{
|
{
|
||||||
// Local Socket
|
// Local Socket
|
||||||
pushFunction(L_p, "createLocalSocket", createLocalSocket);
|
pushFunction(L_p, "createLocalSocket", createLocalSocket);
|
||||||
|
|
||||||
|
// TCP Socket
|
||||||
|
pushFunction(L_p, "createTcpSocket", createTcpSocket);
|
||||||
|
|
||||||
// Socket
|
// Socket
|
||||||
pushFunction(L_p, "socketConnect", socketConnect);
|
pushFunction(L_p, "socketConnect", socketConnect);
|
||||||
pushFunction(L_p, "socketDisconnect", socketDisconnect);
|
pushFunction(L_p, "socketDisconnect", socketDisconnect);
|
||||||
|
@ -49,6 +57,25 @@ int LuaEngineNetwork::createLocalSocket(lua_State *L_p)
|
||||||
return 1;
|
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)
|
int LuaEngineNetwork::socketConnect(lua_State *L_p)
|
||||||
{
|
{
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
static void pushClass(lua_State *L_p);
|
static void pushClass(lua_State *L_p);
|
||||||
static void pushClass(LuaEngine *luaEngine);
|
static void pushClass(LuaEngine *luaEngine);
|
||||||
static int createLocalSocket(lua_State *L_p);
|
static int createLocalSocket(lua_State *L_p);
|
||||||
|
static int createTcpSocket(lua_State *L_p);
|
||||||
static int socketConnect(lua_State *L_p);
|
static int socketConnect(lua_State *L_p);
|
||||||
static int socketDisconnect(lua_State *L_p);
|
static int socketDisconnect(lua_State *L_p);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue