mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +01:00
add socketFlush, tcpSocketStartTLS and luaEngineTLSAvailable
This commit is contained in:
parent
3daf9e69a9
commit
536ca5e539
3 changed files with 66 additions and 4 deletions
|
@ -29,12 +29,17 @@ 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);
|
||||
pushFunction(L_p, "socketFlush", socketFlush);
|
||||
|
||||
// TCP Socket
|
||||
pushFunction(L_p, "createTcpSocket", createTcpSocket);
|
||||
pushFunction(L_p, "tcpSocketStartTLS", tcpSocketStartTLS);
|
||||
|
||||
// TLS
|
||||
pushFunction(L_p, "luaEngineTLSAvailable", luaEngineTLSAvailable);
|
||||
}
|
||||
|
||||
void LuaEngineNetwork::pushClass(LuaEngine *luaEngine)
|
||||
|
@ -69,13 +74,29 @@ int LuaEngineNetwork::createTcpSocket(lua_State *L_p)
|
|||
#ifdef QT_NO_SSL
|
||||
QTcpSocket *tcpSocket = new QTcpSocket(parent);
|
||||
#else
|
||||
QSslSocket *tcpSocket = new QSslSocket(parent);
|
||||
QTcpSocket *tcpSocket;
|
||||
if (QSslSocket::supportsSsl()) {
|
||||
tcpSocket = new QSslSocket(parent);
|
||||
}
|
||||
else {
|
||||
tcpSocket = new QTcpSocket(parent);
|
||||
}
|
||||
#endif
|
||||
tcpSocket->setObjectName(nameForPointer(tcpSocket));
|
||||
pushPointer(L_p, tcpSocket);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineNetwork::luaEngineTLSAvailable(lua_State *L_p)
|
||||
{
|
||||
#ifdef QT_NO_SSL
|
||||
pushVariant(L_p, false);
|
||||
#else
|
||||
pushVariant(L_p, QSslSocket::supportsSsl());
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaEngineNetwork::socketConnect(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
|
@ -111,6 +132,39 @@ int LuaEngineNetwork::socketDisconnect(lua_State *L_p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineNetwork::socketFlush(lua_State *L_p)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL) {
|
||||
if (((QObject*)pointer)->inherits("QAbstractSocket")) {
|
||||
bool isFlushed = ((QAbstractSocket*)pointer)->flush();
|
||||
pushVariant(L_p, isFlushed);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LuaEngineNetwork::tcpSocketStartTLS(lua_State *L_p)
|
||||
{
|
||||
#ifndef QT_NO_SSL
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL) {
|
||||
if (((QObject*)pointer)->inherits("QSslSocket")) {
|
||||
((QSslSocket*)pointer)->startClientEncryption();
|
||||
pushVariant(L_p, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pushVariant(L_p, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QString LuaEngineNetwork::nameForPointer(void *pointer)
|
||||
{
|
||||
QString nameStorage;
|
||||
|
|
|
@ -30,8 +30,11 @@ public:
|
|||
static void pushClass(LuaEngine *luaEngine);
|
||||
static int createLocalSocket(lua_State *L_p);
|
||||
static int createTcpSocket(lua_State *L_p);
|
||||
static int luaEngineTLSAvailable(lua_State *L_p);
|
||||
static int socketConnect(lua_State *L_p);
|
||||
static int socketDisconnect(lua_State *L_p);
|
||||
static int socketFlush(lua_State *L_p);
|
||||
static int tcpSocketStartTLS(lua_State *L_p);
|
||||
|
||||
private:
|
||||
lua_State *L;
|
||||
|
|
|
@ -75,6 +75,11 @@ function main()
|
|||
createLabel("Right", imagesLayout)
|
||||
createSpacerItem(SizePolicyExpanding, SizePolicyMinimum, imagesLayout)
|
||||
|
||||
-- Third Tab
|
||||
local thirdTab = createWidgetTab("Third Tab", tabBar)
|
||||
local thirdTabLayout = createLayout(VerticalLayout, thirdTab)
|
||||
createLabel("<b>The Third Tab is here!</b>", thirdTabLayout)
|
||||
|
||||
-- Last Tab
|
||||
local lastTab = createWidgetTab("Last Tab", tabBar)
|
||||
local lastTabLayout = createLayout(HorizontalLayout, lastTab)
|
||||
|
|
Loading…
Reference in a new issue