mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-11-05 05:26:55 +01:00
fix reading
This commit is contained in:
parent
536ca5e539
commit
0fd63c62e3
2 changed files with 34 additions and 3 deletions
|
@ -100,7 +100,7 @@ int LuaEngineIO::eIORead(lua_State *L_p)
|
||||||
if (pointer != NULL) {
|
if (pointer != NULL) {
|
||||||
if (((QObject*)pointer)->inherits("QIODevice")) {
|
if (((QObject*)pointer)->inherits("QIODevice")) {
|
||||||
const QByteArray readData = ((QIODevice*)pointer)->read(getVariant(L_p, 2).toLongLong());
|
const QByteArray readData = ((QIODevice*)pointer)->read(getVariant(L_p, 2).toLongLong());
|
||||||
pushVariant(L_p, readData);
|
pushVariant(L_p, QString::fromUtf8(readData));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ int LuaEngineIO::eIOReadAll(lua_State *L_p)
|
||||||
if (pointer != NULL) {
|
if (pointer != NULL) {
|
||||||
if (((QObject*)pointer)->inherits("QIODevice")) {
|
if (((QObject*)pointer)->inherits("QIODevice")) {
|
||||||
const QByteArray readData = ((QIODevice*)pointer)->readAll();
|
const QByteArray readData = ((QIODevice*)pointer)->readAll();
|
||||||
pushVariant(L_p, readData);
|
pushVariant(L_p, QString::fromUtf8(readData));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ int LuaEngineIO::eIOReadLine(lua_State *L_p)
|
||||||
if (pointer != NULL) {
|
if (pointer != NULL) {
|
||||||
if (((QObject*)pointer)->inherits("QIODevice")) {
|
if (((QObject*)pointer)->inherits("QIODevice")) {
|
||||||
const QByteArray readData = ((QIODevice*)pointer)->readLine();
|
const QByteArray readData = ((QIODevice*)pointer)->readLine();
|
||||||
pushVariant(L_p, readData);
|
pushVariant(L_p, QString::fromUtf8(readData));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
31
tests/network/network.lua
Normal file
31
tests/network/network.lua
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
local globalLabel
|
||||||
|
|
||||||
|
function main()
|
||||||
|
-- Window
|
||||||
|
mainWindow = createMainWindow("LE TCP Test")
|
||||||
|
local mainLayout = createLayout(VerticalLayout, mainWindow)
|
||||||
|
|
||||||
|
local socket = createTcpSocket()
|
||||||
|
connect(socket, "connected()", "socketConnected")
|
||||||
|
connect(socket, "readyRead()", "socketReadyRead")
|
||||||
|
socketConnect(socket, "syping.de:80")
|
||||||
|
|
||||||
|
globalLabel = createLabel("<b>Connecting...</b>", mainLayout)
|
||||||
|
|
||||||
|
-- Show Window
|
||||||
|
setWidgetSize(mainWindow, 650, 450)
|
||||||
|
showWidget(mainWindow, ShowDefault)
|
||||||
|
return GuiExecuted
|
||||||
|
end
|
||||||
|
|
||||||
|
function socketConnected(socket)
|
||||||
|
setObjectText(globalLabel, "<b>Connected!</b>")
|
||||||
|
eIOWrite(socket, "GET /luaenginetest.html HTTP/1.1\r\nHost: www.syping.de\r\nUser-Agent: LuaEngine\r\nConnection: close\r\n\r\n")
|
||||||
|
socketFlush(socket)
|
||||||
|
end
|
||||||
|
|
||||||
|
function socketReadyRead(socket)
|
||||||
|
setObjectText(globalLabel, "<b>Reading...</b>")
|
||||||
|
local readData = eIOReadAll(socket)
|
||||||
|
setObjectText(globalLabel, "<!DOCTYPE html>" .. readData)
|
||||||
|
end
|
Loading…
Reference in a new issue