diff --git a/src/luaengine/luaengine.pro b/src/luaengine/luaengine.pro index c4f61f6..327b10b 100644 --- a/src/luaengine/luaengine.pro +++ b/src/luaengine/luaengine.pro @@ -25,7 +25,6 @@ DEFINES += LUA_COMPAT_5_2 shared: win32: DEFINES += LUA_BUILD_AS_DLL static: DEFINES += LUAENGINE_STATIC linux: DEFINES += LUA_USE_LINUX - gcc: QMAKE_CFLAGS += -Wno-cast-function-type SOURCES += \ @@ -33,7 +32,8 @@ SOURCES += \ HEADERS += \ luaengine/LuaEngine.h \ - luaengine/LuaEngine_global.h + luaengine/LuaEngine_global.h \ + luaengine/LuaEngine_macro.h SOURCES += \ lua/lapi.c \ diff --git a/src/luaengine/luaengine/LuaEngine_macro.h b/src/luaengine/luaengine/LuaEngine_macro.h new file mode 100644 index 0000000..eac0c9e --- /dev/null +++ b/src/luaengine/luaengine/LuaEngine_macro.h @@ -0,0 +1,29 @@ +/***************************************************************************** +* 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 LUAENGINE_MACRO_H +#define LUAENGINE_MACRO_H + +#define getArguments LuaEngine::getArguments +#define getArgumentCount LuaEngine::getArgumentCount +#define getPointer LuaEngine::getPointer +#define getVariant LuaEngine::getVariant +#define pushFunction LuaEngine::pushFunction +#define pushPointer LuaEngine::pushPointer +#define pushVariant LuaEngine::pushVariant + +#endif // LUAENGINE_MACRO_H diff --git a/src/luaengineapp/luaengineapp.pro b/src/luaengineapp/luaengineapp.pro index b28d509..f938acf 100644 --- a/src/luaengineapp/luaengineapp.pro +++ b/src/luaengineapp/luaengineapp.pro @@ -21,15 +21,16 @@ CONFIG += c++11 static: DEFINES += LUAENGINE_STATIC -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui +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 INCLUDEPATH += \ ../luaengine/lua \ ../luaengine/luaengine \ - ../luaenginegui/luaengine + ../luaenginegui/luaengine \ + ../luaengineos/luaengine SOURCES += \ main.cpp diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index ad89c16..75a1424 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -16,6 +16,7 @@ *****************************************************************************/ #include "LuaEngineGui.h" +#include "LuaEngineOS.h" #include #include #include @@ -54,6 +55,7 @@ int main(int argc, char *argv[]) #endif LuaEngineGui luaEngineGui; + LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.executeLuaScript(luaScript); QVariantList arguments; diff --git a/src/luaenginegui/luaenginegui.pro b/src/luaenginegui/luaenginegui.pro index 1cbd87c..4eeb1a7 100644 --- a/src/luaenginegui/luaenginegui.pro +++ b/src/luaenginegui/luaenginegui.pro @@ -25,7 +25,7 @@ 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 -L$$OUT_PWD/../luaenginegui -lluaengine +unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine INCLUDEPATH += \ ../luaengine/lua \ diff --git a/src/luaengineos/luaengine/LuaEngineOS.cpp b/src/luaengineos/luaengine/LuaEngineOS.cpp new file mode 100644 index 0000000..14d1130 --- /dev/null +++ b/src/luaengineos/luaengine/LuaEngineOS.cpp @@ -0,0 +1,65 @@ +/***************************************************************************** +* 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 "LuaEngine_macro.h" +#include "LuaEngineOS.h" +#include +#include +#include + +void LuaEngineOS::pushClass(lua_State *L_p) +{ + // Process + pushFunction(L_p, "executeProcess", executeProcess); +} + +void LuaEngineOS::pushClass(LuaEngine *luaEngine) +{ + pushClass(luaEngine->luaState()); +} + +int LuaEngineOS::executeProcess(lua_State *L_p) +{ + if (getArgumentCount(L_p) >= 1) { + QProcess *process = new QProcess; + if (getArgumentCount(L_p) >= 2) { + QVariantList arguments = getArguments(L_p); + QStringList processArguments; + QString processPath = arguments.first().toString(); + arguments.removeFirst(); + for (const QVariant &argument : arguments) { + processArguments << argument.toString(); + } + process->start(processPath, processArguments, QProcess::ReadOnly); + } + else { + process->start(getVariant(L_p, 1).toString(), QProcess::ReadOnly); + } + QObject::connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); + pushVariant(L_p, true); + return 1; + } + pushVariant(L_p, false); + return 1; +} + +QString LuaEngineOS::nameForPointer(void *pointer) +{ + QString nameStorage; + QTextStream(&nameStorage) << "LuaEngineOS" << pointer; + return nameStorage; +} diff --git a/src/luaengineos/luaengine/LuaEngineOS.h b/src/luaengineos/luaengine/LuaEngineOS.h new file mode 100644 index 0000000..a411976 --- /dev/null +++ b/src/luaengineos/luaengine/LuaEngineOS.h @@ -0,0 +1,35 @@ +/***************************************************************************** +* 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 LUAENGINEOS_H +#define LUAENGINEOS_H + +#include "LuaEngineOS_global.h" +#include "LuaEngine.h" + +class LUAENGINEOSSHARED_EXPORT LuaEngineOS +{ +public: + static void pushClass(lua_State *L_p); + static void pushClass(LuaEngine *luaEngine); + static int executeProcess(lua_State *L_p); + +private: + static QString nameForPointer(void *pointer); +}; + +#endif // LUAENGINEOS_H diff --git a/src/luaengineos/luaengine/LuaEngineOS_global.h b/src/luaengineos/luaengine/LuaEngineOS_global.h new file mode 100644 index 0000000..d80fdb8 --- /dev/null +++ b/src/luaengineos/luaengine/LuaEngineOS_global.h @@ -0,0 +1,33 @@ +/***************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2018-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 LUAENGINEOS_GLOBAL_H +#define LUAENGINEOS_GLOBAL_H + +#include + +#ifndef LUAENGINE_STATIC +#ifdef LUAENGINEOS_LIBRARY +#define LUAENGINEOSSHARED_EXPORT Q_DECL_EXPORT +#else +#define LUAENGINEOSSHARED_EXPORT Q_DECL_IMPORT +#endif +#else +#define LUAENGINEOSSHARED_EXPORT +#endif + +#endif // LUAENGINEOS_GLOBAL_H diff --git a/src/luaengineos/luaengineos.pro b/src/luaengineos/luaengineos.pro new file mode 100644 index 0000000..8730238 --- /dev/null +++ b/src/luaengineos/luaengineos.pro @@ -0,0 +1,39 @@ +#/***************************************************************************** +#* luaEngine Lua Engine for Qt +#* Copyright (C) 2018-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 = luaengineos +TEMPLATE = lib +CONFIG += c++11 + +DEFINES += LUAENGINEOS_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/LuaEngineOS.cpp + +HEADERS += \ + luaengine/LuaEngineOS.h \ + luaengine/LuaEngineOS_global.h diff --git a/src/luaenginerun/luaenginerun.pro b/src/luaenginerun/luaenginerun.pro index 24e2138..34467c8 100644 --- a/src/luaenginerun/luaenginerun.pro +++ b/src/luaenginerun/luaenginerun.pro @@ -21,15 +21,16 @@ CONFIG += c++11 static: DEFINES += LUAENGINE_STATIC -CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -lluaenginegui -CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui -unix: LIBS += -L$$OUT_PWD/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui +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 INCLUDEPATH += \ ../luaengine/lua \ ../luaengine/luaengine \ - ../luaenginegui/luaengine + ../luaenginegui/luaengine \ + ../luaengineos/luaengine SOURCES += \ main.cpp diff --git a/src/luaenginerun/main.cpp b/src/luaenginerun/main.cpp index 4a160cf..550df50 100644 --- a/src/luaenginerun/main.cpp +++ b/src/luaenginerun/main.cpp @@ -16,6 +16,7 @@ *****************************************************************************/ #include "LuaEngineGui.h" +#include "LuaEngineOS.h" #include #include #include @@ -45,6 +46,7 @@ int main(int argc, char *argv[]) QFile luaScript(arguments.first().toString()); LuaEngineGui luaEngineGui; + LuaEngineOS::pushClass(&luaEngineGui); luaEngineGui.executeLuaScript(&luaScript); if (luaEngineGui.executeLuaFunction("main", arguments, true)) { diff --git a/src/src.pro b/src/src.pro index 9575fce..6a55f5b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -19,7 +19,8 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS += luaengine \ - luaenginegui + luaenginegui \ + luaengineos CONFIG(WITH_LUAENGINEAPP): SUBDIRS += luaengineapp CONFIG(WITH_LUAENGINERUN): SUBDIRS += luaenginerun