mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 03:45:32 +01:00
add read and write eIO functions
This commit is contained in:
parent
64a3508441
commit
9b17fe144d
2 changed files with 68 additions and 0 deletions
|
@ -43,6 +43,12 @@ void LuaEngineIO::pushClass(lua_State *L_p)
|
|||
pushVariant(L_p, "Directories", (int)2);
|
||||
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
|
||||
pushFunction(L_p, "checkFileExists", checkFileExists);
|
||||
pushFunction(L_p, "linkFile", linkFile);
|
||||
|
@ -87,6 +93,64 @@ int LuaEngineIO::checkFileExists(lua_State *L_p)
|
|||
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)
|
||||
{
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
|
|
|
@ -32,6 +32,10 @@ public:
|
|||
static void pushClass(LuaEngine *luaEngine);
|
||||
static int checkDirectoryExists(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 getDirectoryPath(lua_State *L_p);
|
||||
static int linkFile(lua_State *L_p);
|
||||
|
|
Loading…
Reference in a new issue