add read and write eIO functions

This commit is contained in:
Syping 2020-07-03 19:18:44 +02:00
parent 64a3508441
commit 9b17fe144d
2 changed files with 68 additions and 0 deletions

View file

@ -43,6 +43,12 @@ void LuaEngineIO::pushClass(lua_State *L_p)
pushVariant(L_p, "Directories", (int)2); pushVariant(L_p, "Directories", (int)2);
pushVariant(L_p, "Subdirectories", (int)4); pushVariant(L_p, "Subdirectories", (int)4);
// Engine IO
pushFunction(L_p, "eIORead", eIORead);
pushFunction(L_p, "eIOReadAll", eIOReadAll);
pushFunction(L_p, "eIOReadLine", eIOReadLine);
pushFunction(L_p, "eIOWrite", eIOWrite);
// File // File
pushFunction(L_p, "checkFileExists", checkFileExists); pushFunction(L_p, "checkFileExists", checkFileExists);
pushFunction(L_p, "linkFile", linkFile); pushFunction(L_p, "linkFile", linkFile);
@ -87,6 +93,64 @@ int LuaEngineIO::checkFileExists(lua_State *L_p)
return 1; return 1;
} }
int LuaEngineIO::eIORead(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QIODevice")) {
const QByteArray readData = ((QIODevice*)pointer)->read(getVariant(L_p, 2).toLongLong());
pushVariant(L_p, readData);
return 1;
}
}
}
return 0;
}
int LuaEngineIO::eIOReadAll(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QIODevice")) {
const QByteArray readData = ((QIODevice*)pointer)->readAll();
pushVariant(L_p, readData);
return 1;
}
}
}
return 0;
}
int LuaEngineIO::eIOReadLine(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QIODevice")) {
const QByteArray readData = ((QIODevice*)pointer)->readLine();
pushVariant(L_p, readData);
return 1;
}
}
}
return 0;
}
int LuaEngineIO::eIOWrite(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QIODevice")) {
((QIODevice*)pointer)->write(getVariant(L_p, 2).toByteArray());
}
}
}
return 0;
}
int LuaEngineIO::getDirectoryContent(lua_State *L_p) int LuaEngineIO::getDirectoryContent(lua_State *L_p)
{ {
if (getArgumentCount(L_p) >= 1) { if (getArgumentCount(L_p) >= 1) {

View file

@ -32,6 +32,10 @@ public:
static void pushClass(LuaEngine *luaEngine); static void pushClass(LuaEngine *luaEngine);
static int checkDirectoryExists(lua_State *L_p); static int checkDirectoryExists(lua_State *L_p);
static int checkFileExists(lua_State *L_p); static int checkFileExists(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);
static int eIOWrite(lua_State *L_p);
static int getDirectoryContent(lua_State *L_p); static int getDirectoryContent(lua_State *L_p);
static int getDirectoryPath(lua_State *L_p); static int getDirectoryPath(lua_State *L_p);
static int linkFile(lua_State *L_p); static int linkFile(lua_State *L_p);