From dacc42683875dbf6199abefe5b03ff55c1fbd588 Mon Sep 17 00:00:00 2001 From: Syping Date: Mon, 27 Jul 2020 16:54:42 +0200 Subject: [PATCH] add eIOBytesAvailable and eIOCanReadLine --- src/luaengineio/luaengine/LuaEngineIO.cpp | 30 +++++++++++++++++++++++ src/luaengineio/luaengine/LuaEngineIO.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/luaengineio/luaengine/LuaEngineIO.cpp b/src/luaengineio/luaengine/LuaEngineIO.cpp index 7b4808c..ca1d168 100644 --- a/src/luaengineio/luaengine/LuaEngineIO.cpp +++ b/src/luaengineio/luaengine/LuaEngineIO.cpp @@ -44,6 +44,8 @@ void LuaEngineIO::pushClass(lua_State *L_p) pushVariant(L_p, "Subdirectories", (int)4); // Engine IO + pushFunction(L_p, "eIOBytesAvailable", eIOBytesAvailable); + pushFunction(L_p, "eIOCanReadLine", eIOCanReadLine); pushFunction(L_p, "eIORead", eIORead); pushFunction(L_p, "eIOReadAll", eIOReadAll); pushFunction(L_p, "eIOReadLine", eIOReadLine); @@ -93,6 +95,34 @@ int LuaEngineIO::checkFileExists(lua_State *L_p) return 1; } +int LuaEngineIO::eIOBytesAvailable(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QIODevice")) { + pushVariant(L_p, ((QIODevice*)pointer)->bytesAvailable()); + return 1; + } + } + } + return 0; +} + +int LuaEngineIO::eIOCanReadLine(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + void *pointer = getPointer(L_p, 1); + if (pointer != NULL) { + if (((QObject*)pointer)->inherits("QIODevice")) { + pushVariant(L_p, ((QIODevice*)pointer)->canReadLine()); + return 1; + } + } + } + return 0; +} + int LuaEngineIO::eIORead(lua_State *L_p) { if (getArgumentCount(L_p) >= 2) { diff --git a/src/luaengineio/luaengine/LuaEngineIO.h b/src/luaengineio/luaengine/LuaEngineIO.h index 8a28322..be02961 100644 --- a/src/luaengineio/luaengine/LuaEngineIO.h +++ b/src/luaengineio/luaengine/LuaEngineIO.h @@ -32,6 +32,8 @@ public: static void pushClass(LuaEngine *luaEngine); static int checkDirectoryExists(lua_State *L_p); static int checkFileExists(lua_State *L_p); + static int eIOBytesAvailable(lua_State *L_p); + static int eIOCanReadLine(lua_State *L_p); static int eIORead(lua_State *L_p); static int eIOReadAll(lua_State *L_p); static int eIOReadLine(lua_State *L_p);