diff --git a/src/luaengineapp/luaengineapp.pro b/src/luaengineapp/luaengineapp.pro index d47dec2..7512de1 100644 --- a/src/luaengineapp/luaengineapp.pro +++ b/src/luaengineapp/luaengineapp.pro @@ -21,15 +21,15 @@ CONFIG += c++11 static: DEFINES += LUAENGINE_STATIC -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine -unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine -win32: LIBS += -luser32 +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaengineio/debug -lluaengineio -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaengineio/release -lluaengineio -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine +unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaengineio -lluaengineio -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine INCLUDEPATH += \ ../luaengine/lua \ ../luaengine/luaengine \ ../luaenginegui/luaengine \ + ../luaengineio/luaengine \ ../luaengineos/luaengine SOURCES += \ diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index add2bf5..9074f5c 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -16,6 +16,7 @@ *****************************************************************************/ #include "LuaEngineGui.h" +#include "LuaEngineIO.h" #include "LuaEngineOS.h" #include #include @@ -52,6 +53,7 @@ int main(int argc, char *argv[]) #endif LuaEngineGui luaEngineGui; + LuaEngineIO::pushClass(&luaEngineGui); LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.executeLuaScript(luaScript); diff --git a/src/luaengineio/luaengine/LuaEngineIO.cpp b/src/luaengineio/luaengine/LuaEngineIO.cpp new file mode 100644 index 0000000..c2b17e6 --- /dev/null +++ b/src/luaengineio/luaengine/LuaEngineIO.cpp @@ -0,0 +1,110 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2019 Syping +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*****************************************************************************/ + +#include "LuaEngineIO.h" +#include +#include +#include +#include +#include +#ifdef Q_OS_WIN +#include "windows.h" +#include +#else +#include "unistd.h" +#endif + +LuaEngineIO::LuaEngineIO(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries) +{ + L = luaState(); + pushClass(L); +} + +void LuaEngineIO::pushClass(lua_State *L_p) +{ + // Directory + pushFunction(L_p, "directoryListFiles", directoryListFiles); + + // File + pushFunction(L_p, "linkFile", linkFile); + pushVariant(L_p, "Symlink", (int)0); + pushVariant(L_p, "Hardlink", (int)1); +} + +void LuaEngineIO::pushClass(LuaEngine *luaEngine) +{ + pushClass(luaEngine->luaState()); +} + +int LuaEngineIO::directoryListFiles(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + QStringList directories; + QStringList nameFilters; + QString directory = getVariant(L_p, 1).toString(); + if (getArgumentCount(L_p) >= 2) { + nameFilters << getVariant(L_p, 2).toString(); + } + QDirIterator dirIterator(directory, nameFilters, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); + while (dirIterator.hasNext()) { + directories << dirIterator.next(); + } + pushVariant(L_p, directories); + return 1; + } + return 0; +} + +int LuaEngineIO::linkFile(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 2) { + bool symlinkMode = true; + if (getArgumentCount(L_p) >= 3 && getVariant(L_p, 3).toInt() == 1) { + symlinkMode = false; + } + bool linkSucceeded = false; + if (symlinkMode) { +#ifdef Q_OS_WIN + QString targetFile = getVariant(L_p, 2).toString(); + if (targetFile.right(4) != ".lnk") { + targetFile += ".lnk"; + } + linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), targetFile); +#else + linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), getVariant(L_p, 2).toString()); +#endif + } + else { +#ifdef Q_OS_WIN + linkSucceeded = CreateHardLinkW(getVariant(L_p, 2).toString().toStdWString().c_str(), getVariant(L_p, 1).toString().toStdWString().c_str(), NULL); +#else + linkSucceeded = link(getVariant(L_p, 1).toString().toUtf8().data(), getVariant(L_p, 2).toString().toUtf8().data()); +#endif + } + pushVariant(L_p, linkSucceeded); + return 1; + } + getVariant(L_p, false); + return 1; +} + +QString LuaEngineIO::nameForPointer(void *pointer) +{ + QString nameStorage; + QTextStream(&nameStorage) << "LuaEngineIO" << pointer; + return nameStorage; +} diff --git a/src/luaengineio/luaengine/LuaEngineIO.h b/src/luaengineio/luaengine/LuaEngineIO.h new file mode 100644 index 0000000..6b375ed --- /dev/null +++ b/src/luaengineio/luaengine/LuaEngineIO.h @@ -0,0 +1,41 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2019 Syping +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*****************************************************************************/ + +#ifndef LUAENGINEIO_H +#define LUAENGINEIO_H + +#include "LuaEngineIO_global.h" +#include "LuaEngine.h" +#include +#include + +class LUAENGINEIOSHARED_EXPORT LuaEngineIO : public LuaEngine +{ + Q_OBJECT +public: + LuaEngineIO(QObject *parent = nullptr, bool loadBaseLibraries = true); + static void pushClass(lua_State *L_p); + static void pushClass(LuaEngine *luaEngine); + static int directoryListFiles(lua_State *L_p); + static int linkFile(lua_State *L_p); + +private: + lua_State *L; + static QString nameForPointer(void *pointer); +}; + +#endif // LUAENGINEIO_H diff --git a/src/luaengineio/luaengine/LuaEngineIO_global.h b/src/luaengineio/luaengine/LuaEngineIO_global.h new file mode 100644 index 0000000..3b908cb --- /dev/null +++ b/src/luaengineio/luaengine/LuaEngineIO_global.h @@ -0,0 +1,33 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2019 Syping +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*****************************************************************************/ + +#ifndef LUAENGINEIO_GLOBAL_H +#define LUAENGINEIO_GLOBAL_H + +#include + +#ifndef LUAENGINE_STATIC +#ifdef LUAENGINEIO_LIBRARY +#define LUAENGINEIOSHARED_EXPORT Q_DECL_EXPORT +#else +#define LUAENGINEIOSHARED_EXPORT Q_DECL_IMPORT +#endif +#else +#define LUAENGINEIOSHARED_EXPORT +#endif + +#endif // LUAENGINEIO_GLOBAL_H diff --git a/src/luaengineio/luaengineio.pro b/src/luaengineio/luaengineio.pro new file mode 100644 index 0000000..1edd56a --- /dev/null +++ b/src/luaengineio/luaengineio.pro @@ -0,0 +1,49 @@ +#/***************************************************************************** +#* luaEngine Lua Engine for Qt +#* Copyright (C) 2019 Syping +#* +#* Licensed under the Apache License, Version 2.0 (the "License"); +#* you may not use this file except in compliance with the License. +#* You may obtain a copy of the License at +#* +#* http://www.apache.org/licenses/LICENSE-2.0 +#* +#* Unless required by applicable law or agreed to in writing, software +#* distributed under the License is distributed on an "AS IS" BASIS, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#*****************************************************************************/ + +QT += core +TARGET = luaengineio +TEMPLATE = lib +CONFIG += c++11 \ + skip_target_version_ext +VERSION = 0.1 + +DEFINES += LUAENGINEIO_LIBRARY +static: DEFINES += LUAENGINE_STATIC + +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine +unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine + +INCLUDEPATH += \ + ../luaengine/lua \ + ../luaengine/luaengine + +SOURCES += \ + luaengine/LuaEngineIO.cpp + +HEADERS += \ + luaengine/LuaEngineIO.h \ + luaengine/LuaEngineIO_global.h + +win32 { + RC_LANG = 0x0 + QMAKE_TARGET_COMPANY = "Syping" + QMAKE_TARGET_DESCRIPTION = "LuaEngine I/O Library" + QMAKE_TARGET_COPYRIGHT = "Copyright (c) 2019 Syping" + QMAKE_TARGET_PRODUCT = "luaengineio" +} diff --git a/src/luaengineos/luaengine/LuaEngineOS.cpp b/src/luaengineos/luaengine/LuaEngineOS.cpp index 7dd64d9..3515000 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.cpp +++ b/src/luaengineos/luaengine/LuaEngineOS.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #ifdef Q_OS_WIN #include "windows.h" @@ -38,14 +37,6 @@ LuaEngineOS::LuaEngineOS(QObject *parent, bool loadBaseLibraries) : LuaEngine(pa void LuaEngineOS::pushClass(lua_State *L_p) { - // Directory - pushFunction(L_p, "directoryListFiles", directoryListFiles); - - // File - pushFunction(L_p, "linkFile", linkFile); - pushVariant(L_p, "Symlink", (int)0); - pushVariant(L_p, "Hardlink", (int)1); - // Process pushFunction(L_p, "executeProcess", executeProcess); } @@ -55,58 +46,6 @@ void LuaEngineOS::pushClass(LuaEngine *luaEngine) pushClass(luaEngine->luaState()); } -int LuaEngineOS::directoryListFiles(lua_State *L_p) -{ - if (getArgumentCount(L_p) >= 1) { - QStringList directories; - QStringList nameFilters; - QString directory = getVariant(L_p, 1).toString(); - if (getArgumentCount(L_p) >= 2) { - nameFilters << getVariant(L_p, 2).toString(); - } - QDirIterator dirIterator(directory, nameFilters, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories); - while (dirIterator.hasNext()) { - directories << dirIterator.next(); - } - pushVariant(L_p, directories); - return 1; - } - return 0; -} - -int LuaEngineOS::linkFile(lua_State *L_p) -{ - if (getArgumentCount(L_p) >= 2) { - bool symlinkMode = true; - if (getArgumentCount(L_p) >= 3 && getVariant(L_p, 3).toInt() == 1) { - symlinkMode = false; - } - bool linkSucceeded = false; - if (symlinkMode) { -#ifdef Q_OS_WIN - QString targetFile = getVariant(L_p, 2).toString(); - if (targetFile.right(4) != ".lnk") { - targetFile += ".lnk"; - } - linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), targetFile); -#else - linkSucceeded = QFile::link(getVariant(L_p, 1).toString(), getVariant(L_p, 2).toString()); -#endif - } - else { -#ifdef Q_OS_WIN - linkSucceeded = CreateHardLinkW(getVariant(L_p, 2).toString().toStdWString().c_str(), getVariant(L_p, 1).toString().toStdWString().c_str(), NULL); -#else - linkSucceeded = link(getVariant(L_p, 1).toString().toUtf8().data(), getVariant(L_p, 2).toString().toUtf8().data()); -#endif - } - pushVariant(L_p, linkSucceeded); - return 1; - } - getVariant(L_p, false); - return 1; -} - int LuaEngineOS::executeProcess(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { diff --git a/src/luaengineos/luaengine/LuaEngineOS.h b/src/luaengineos/luaengine/LuaEngineOS.h index a67d4de..8d2f2ad 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.h +++ b/src/luaengineos/luaengine/LuaEngineOS.h @@ -30,8 +30,6 @@ public: LuaEngineOS(QObject *parent = nullptr, bool loadBaseLibraries = true); static void pushClass(lua_State *L_p); static void pushClass(LuaEngine *luaEngine); - static int directoryListFiles(lua_State *L_p); - static int linkFile(lua_State *L_p); static int executeProcess(lua_State *L_p); private: diff --git a/src/luaengineos/luaengine/LuaEngineOS_global.h b/src/luaengineos/luaengine/LuaEngineOS_global.h index d80fdb8..e4a7fce 100644 --- a/src/luaengineos/luaengine/LuaEngineOS_global.h +++ b/src/luaengineos/luaengine/LuaEngineOS_global.h @@ -1,6 +1,6 @@ /***************************************************************************** * luaEngine Lua Engine for Qt -* Copyright (C) 2018-2019 Syping +* Copyright (C) 2019 Syping * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/luaenginerun/luaenginerun.pro b/src/luaenginerun/luaenginerun.pro index 34467c8..25e77e5 100644 --- a/src/luaenginerun/luaenginerun.pro +++ b/src/luaenginerun/luaenginerun.pro @@ -21,15 +21,15 @@ CONFIG += c++11 static: DEFINES += LUAENGINE_STATIC -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine -unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine -win32: LIBS += -luser32 +CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lluaengineos -L$$OUT_PWD/../luaengineio/debug -lluaengineio -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -L$$OUT_PWD/../luaengine/debug -lluaengine +CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lluaengineos -L$$OUT_PWD/../luaengineio/release -lluaengineio -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -L$$OUT_PWD/../luaengine/release -lluaengine +unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaengineio -lluaengineio -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine INCLUDEPATH += \ ../luaengine/lua \ ../luaengine/luaengine \ ../luaenginegui/luaengine \ + ../luaengineio/luaengine \ ../luaengineos/luaengine SOURCES += \ diff --git a/src/luaenginerun/main.cpp b/src/luaenginerun/main.cpp index 550df50..56745b3 100644 --- a/src/luaenginerun/main.cpp +++ b/src/luaenginerun/main.cpp @@ -16,6 +16,7 @@ *****************************************************************************/ #include "LuaEngineGui.h" +#include "LuaEngineIO.h" #include "LuaEngineOS.h" #include #include @@ -46,6 +47,7 @@ int main(int argc, char *argv[]) QFile luaScript(arguments.first().toString()); LuaEngineGui luaEngineGui; + LuaEngineIO::pushClass(&luaEngineGui); LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.executeLuaScript(&luaScript); diff --git a/src/src.pro b/src/src.pro index 6a55f5b..26101ef 100644 --- a/src/src.pro +++ b/src/src.pro @@ -20,6 +20,7 @@ CONFIG += ordered SUBDIRS += luaengine \ luaenginegui \ + luaengineio \ luaengineos CONFIG(WITH_LUAENGINEAPP): SUBDIRS += luaengineapp