mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 20:05:30 +01:00
add executeProcess function and OS library
This commit is contained in:
parent
e189120982
commit
7773d84176
12 changed files with 220 additions and 12 deletions
|
@ -25,7 +25,6 @@ DEFINES += LUA_COMPAT_5_2
|
||||||
shared: win32: DEFINES += LUA_BUILD_AS_DLL
|
shared: win32: DEFINES += LUA_BUILD_AS_DLL
|
||||||
static: DEFINES += LUAENGINE_STATIC
|
static: DEFINES += LUAENGINE_STATIC
|
||||||
linux: DEFINES += LUA_USE_LINUX
|
linux: DEFINES += LUA_USE_LINUX
|
||||||
|
|
||||||
gcc: QMAKE_CFLAGS += -Wno-cast-function-type
|
gcc: QMAKE_CFLAGS += -Wno-cast-function-type
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
@ -33,7 +32,8 @@ SOURCES += \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
luaengine/LuaEngine.h \
|
luaengine/LuaEngine.h \
|
||||||
luaengine/LuaEngine_global.h
|
luaengine/LuaEngine_global.h \
|
||||||
|
luaengine/LuaEngine_macro.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
lua/lapi.c \
|
lua/lapi.c \
|
||||||
|
|
29
src/luaengine/luaengine/LuaEngine_macro.h
Normal file
29
src/luaengine/luaengine/LuaEngine_macro.h
Normal file
|
@ -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
|
|
@ -21,15 +21,16 @@ CONFIG += c++11
|
||||||
|
|
||||||
static: DEFINES += LUAENGINE_STATIC
|
static: DEFINES += LUAENGINE_STATIC
|
||||||
|
|
||||||
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -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/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui
|
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/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui
|
unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine
|
||||||
win32: LIBS += -luser32
|
win32: LIBS += -luser32
|
||||||
|
|
||||||
INCLUDEPATH += \
|
INCLUDEPATH += \
|
||||||
../luaengine/lua \
|
../luaengine/lua \
|
||||||
../luaengine/luaengine \
|
../luaengine/luaengine \
|
||||||
../luaenginegui/luaengine
|
../luaenginegui/luaengine \
|
||||||
|
../luaengineos/luaengine
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "LuaEngineGui.h"
|
#include "LuaEngineGui.h"
|
||||||
|
#include "LuaEngineOS.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -54,6 +55,7 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LuaEngineGui luaEngineGui;
|
LuaEngineGui luaEngineGui;
|
||||||
|
LuaEngineOS::pushClass(&luaEngineGui);
|
||||||
luaEngineGui.executeLuaScript(luaScript);
|
luaEngineGui.executeLuaScript(luaScript);
|
||||||
|
|
||||||
QVariantList arguments;
|
QVariantList arguments;
|
||||||
|
|
|
@ -25,7 +25,7 @@ static: DEFINES += LUAENGINE_STATIC
|
||||||
|
|
||||||
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine
|
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine
|
||||||
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/release -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 += \
|
INCLUDEPATH += \
|
||||||
../luaengine/lua \
|
../luaengine/lua \
|
||||||
|
|
65
src/luaengineos/luaengine/LuaEngineOS.cpp
Normal file
65
src/luaengineos/luaengine/LuaEngineOS.cpp
Normal file
|
@ -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 <QTextStream>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
35
src/luaengineos/luaengine/LuaEngineOS.h
Normal file
35
src/luaengineos/luaengine/LuaEngineOS.h
Normal file
|
@ -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
|
33
src/luaengineos/luaengine/LuaEngineOS_global.h
Normal file
33
src/luaengineos/luaengine/LuaEngineOS_global.h
Normal file
|
@ -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 <QtCore/qglobal.h>
|
||||||
|
|
||||||
|
#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
|
39
src/luaengineos/luaengineos.pro
Normal file
39
src/luaengineos/luaengineos.pro
Normal file
|
@ -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
|
|
@ -21,15 +21,16 @@ CONFIG += c++11
|
||||||
|
|
||||||
static: DEFINES += LUAENGINE_STATIC
|
static: DEFINES += LUAENGINE_STATIC
|
||||||
|
|
||||||
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengine/debug -lluaengine -L$$OUT_PWD/../luaenginegui/debug -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/../luaengine/release -lluaengine -L$$OUT_PWD/../luaenginegui/release -lluaenginegui
|
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/../luaengine -lluaengine -L$$OUT_PWD/../luaenginegui -lluaenginegui
|
unix: LIBS += -L$$OUT_PWD/../luaengineos -lluaengineos -L$$OUT_PWD/../luaenginegui -lluaenginegui -L$$OUT_PWD/../luaengine -lluaengine
|
||||||
win32: LIBS += -luser32
|
win32: LIBS += -luser32
|
||||||
|
|
||||||
INCLUDEPATH += \
|
INCLUDEPATH += \
|
||||||
../luaengine/lua \
|
../luaengine/lua \
|
||||||
../luaengine/luaengine \
|
../luaengine/luaengine \
|
||||||
../luaenginegui/luaengine
|
../luaenginegui/luaengine \
|
||||||
|
../luaengineos/luaengine
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "LuaEngineGui.h"
|
#include "LuaEngineGui.h"
|
||||||
|
#include "LuaEngineOS.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
@ -45,6 +46,7 @@ int main(int argc, char *argv[])
|
||||||
QFile luaScript(arguments.first().toString());
|
QFile luaScript(arguments.first().toString());
|
||||||
|
|
||||||
LuaEngineGui luaEngineGui;
|
LuaEngineGui luaEngineGui;
|
||||||
|
LuaEngineOS::pushClass(&luaEngineGui);
|
||||||
luaEngineGui.executeLuaScript(&luaScript);
|
luaEngineGui.executeLuaScript(&luaScript);
|
||||||
|
|
||||||
if (luaEngineGui.executeLuaFunction("main", arguments, true)) {
|
if (luaEngineGui.executeLuaFunction("main", arguments, true)) {
|
||||||
|
|
|
@ -19,7 +19,8 @@ TEMPLATE = subdirs
|
||||||
CONFIG += ordered
|
CONFIG += ordered
|
||||||
|
|
||||||
SUBDIRS += luaengine \
|
SUBDIRS += luaengine \
|
||||||
luaenginegui
|
luaenginegui \
|
||||||
|
luaengineos
|
||||||
|
|
||||||
CONFIG(WITH_LUAENGINEAPP): SUBDIRS += luaengineapp
|
CONFIG(WITH_LUAENGINEAPP): SUBDIRS += luaengineapp
|
||||||
CONFIG(WITH_LUAENGINERUN): SUBDIRS += luaenginerun
|
CONFIG(WITH_LUAENGINERUN): SUBDIRS += luaenginerun
|
||||||
|
|
Loading…
Reference in a new issue