mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
added quit + CLI
This commit is contained in:
parent
50dddccf27
commit
2a3aa0af59
6 changed files with 169 additions and 1 deletions
|
@ -66,6 +66,7 @@ int main(int argc, char *argv[])
|
||||||
LuaEngineNetwork::pushClass(&luaEngineGui);
|
LuaEngineNetwork::pushClass(&luaEngineGui);
|
||||||
LuaEngineOS::pushClass(&luaEngineGui);
|
LuaEngineOS::pushClass(&luaEngineGui);
|
||||||
luaEngineGui.pushVariant("_LuaEngineRT", rtPath);
|
luaEngineGui.pushVariant("_LuaEngineRT", rtPath);
|
||||||
|
luaEngineGui.setProperty("EngineMode", "GUI");
|
||||||
luaEngineGui.setProperty("EngineType", "Runtime");
|
luaEngineGui.setProperty("EngineType", "Runtime");
|
||||||
luaEngineGui.setProperty("ScriptPath", scriptPath);
|
luaEngineGui.setProperty("ScriptPath", scriptPath);
|
||||||
luaEngineGui.executeLuaScript(luaScript.readAll());
|
luaEngineGui.executeLuaScript(luaScript.readAll());
|
||||||
|
@ -76,7 +77,7 @@ int main(int argc, char *argv[])
|
||||||
return variant.toInt();
|
return variant.toInt();
|
||||||
}
|
}
|
||||||
else if (variant.type() == QVariant::String) {
|
else if (variant.type() == QVariant::String) {
|
||||||
if (variant.toString() == "GuiExecuted") {
|
if (variant.toString() == "GuiExecuted" || variant.toString() == "CLIExecuted") {
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
63
src/luaenginecli/luaenginecli.pro
Normal file
63
src/luaenginecli/luaenginecli.pro
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#/*****************************************************************************
|
||||||
|
#* luaEngine Lua Engine for Qt
|
||||||
|
#* Copyright (C) 2020 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 += network
|
||||||
|
QT -= gui
|
||||||
|
TARGET = luaenginecli
|
||||||
|
CONFIG += c++11 \
|
||||||
|
console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
VERSION = 0.1
|
||||||
|
|
||||||
|
static: DEFINES += LUAENGINE_STATIC
|
||||||
|
|
||||||
|
# PROJECT PREFIX
|
||||||
|
unix {
|
||||||
|
isEmpty(LUAENGINE_PREFIX): LUAENGINE_PREFIX = /usr/local
|
||||||
|
isEmpty(LUAENGINE_BINDIR): LUAENGINE_BINDIR = $$LUAENGINE_PREFIX/bin
|
||||||
|
isEmpty(LUAENGINE_LIBDIR): LUAENGINE_LIBDIR = $$LUAENGINE_PREFIX/lib
|
||||||
|
}
|
||||||
|
|
||||||
|
unix: LIBS += "-Wl,-rpath,\'$$LUAENGINE_LIBDIR\'" -L$$OUT_PWD/../luaengineos -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio -lLuaEngineIO -L$$OUT_PWD/../luaenginegui -lLuaEngineGui -L$$OUT_PWD/../luaenginecore -lLuaEngine
|
||||||
|
CONFIG(debug, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/debug -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/debug -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/debug -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/debug -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/debug -lLuaEngine
|
||||||
|
CONFIG(release, debug|release): win32: LIBS += -L$$OUT_PWD/../luaengineos/release -lLuaEngineOS -L$$OUT_PWD/../luaenginenetwork/release -lLuaEngineNetwork -L$$OUT_PWD/../luaengineio/release -lLuaEngineIO -L$$OUT_PWD/../luaenginegui/release -lLuaEngineGui -L$$OUT_PWD/../luaenginecore/release -lLuaEngine
|
||||||
|
|
||||||
|
INCLUDEPATH += \
|
||||||
|
../luaenginecore/luaengine \
|
||||||
|
../luaenginegui/luaengine \
|
||||||
|
../luaengineio/luaengine \
|
||||||
|
../luaenginenetwork/luaengine \
|
||||||
|
../luaengineos/luaengine
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
include(../luaenginecore/lua_module.pri)
|
||||||
|
|
||||||
|
unix {
|
||||||
|
target.path = $$LUAENGINE_BINDIR
|
||||||
|
INSTALLS += target
|
||||||
|
}
|
||||||
|
|
||||||
|
win32 {
|
||||||
|
RC_LANG = 0x0
|
||||||
|
RC_ICONS = ../../res/lua.ico
|
||||||
|
QMAKE_TARGET_COMPANY = "Syping"
|
||||||
|
QMAKE_TARGET_DESCRIPTION = "LuaEngine CLI Runtime"
|
||||||
|
QMAKE_TARGET_COPYRIGHT = "Copyright (c) 2020 Syping"
|
||||||
|
QMAKE_TARGET_PRODUCT = "luaenginecli"
|
||||||
|
}
|
84
src/luaenginecli/main.cpp
Normal file
84
src/luaenginecli/main.cpp
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "LuaEngineNetwork.h"
|
||||||
|
#include "LuaEngineIO.h"
|
||||||
|
#include "LuaEngineOS.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
QVariantList arguments;
|
||||||
|
for (const QString &argument : a.arguments()) {
|
||||||
|
arguments << QVariant::fromValue(argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.length() >= 2) {
|
||||||
|
QVariant rtPath = arguments.first();
|
||||||
|
arguments.removeFirst();
|
||||||
|
QVariant scriptPath = arguments.first();
|
||||||
|
QFile luaScript(scriptPath.toString());
|
||||||
|
if (!luaScript.open(QIODevice::ReadOnly)) {
|
||||||
|
QTextStream(stderr) << "Error: Failed to open \"" << arguments.first().toString() << "\"." << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QString::fromUtf8(luaScript.read(2)) == "#!") {
|
||||||
|
luaScript.readLine();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
luaScript.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaEngine luaEngine;
|
||||||
|
LuaEngineIO::pushClass(&luaEngine);
|
||||||
|
LuaEngineNetwork::pushClass(&luaEngine);
|
||||||
|
LuaEngineOS::pushClass(&luaEngine);
|
||||||
|
luaEngine.pushVariant("_LuaEngineRT", rtPath);
|
||||||
|
luaEngine.setProperty("EngineMode", "CLI");
|
||||||
|
luaEngine.setProperty("EngineType", "Runtime");
|
||||||
|
luaEngine.setProperty("ScriptPath", scriptPath);
|
||||||
|
luaEngine.executeLuaScript(luaScript.readAll());
|
||||||
|
|
||||||
|
if (luaEngine.executeLuaFunction("main", arguments, true)) {
|
||||||
|
QVariant variant = luaEngine.returnVariant();
|
||||||
|
if (variant.type() == QVariant::Int || variant.type() == QVariant::LongLong) {
|
||||||
|
return variant.toInt();
|
||||||
|
}
|
||||||
|
else if (variant.type() == QVariant::String) {
|
||||||
|
if (variant.toString() == "CLIExecuted") {
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,7 @@
|
||||||
#define LUA_LIB
|
#define LUA_LIB
|
||||||
#include "LuaEngine.h"
|
#include "LuaEngine.h"
|
||||||
#include "LuaEngineRegistry.h"
|
#include "LuaEngineRegistry.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
|
||||||
|
@ -30,11 +31,13 @@ LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
|
||||||
|
|
||||||
pushVariant("DeleteInstant", 0);
|
pushVariant("DeleteInstant", 0);
|
||||||
pushVariant("DeleteLater", 1);
|
pushVariant("DeleteLater", 1);
|
||||||
|
pushVariant("CLIExecuted", "CLIExecuted");
|
||||||
pushFunction("delete", luaObjectDelete_p);
|
pushFunction("delete", luaObjectDelete_p);
|
||||||
pushFunction("connect", luaTriggerConnect_p);
|
pushFunction("connect", luaTriggerConnect_p);
|
||||||
pushFunction("disconnect", luaTriggerDisconnect_p);
|
pushFunction("disconnect", luaTriggerDisconnect_p);
|
||||||
pushFunction("getObjectParent", luaObjectGetParent_p);
|
pushFunction("getObjectParent", luaObjectGetParent_p);
|
||||||
pushFunction("setObjectParent", luaObjectSetParent_p);
|
pushFunction("setObjectParent", luaObjectSetParent_p);
|
||||||
|
pushFunction("luaEngineQuit", luaEngineQuit_p);
|
||||||
pushFunction("luaEngineVersion", luaEngineVersion_p);
|
pushFunction("luaEngineVersion", luaEngineVersion_p);
|
||||||
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
|
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +65,21 @@ int LuaEngine::luaEngineWriter_p(lua_State *L_p, const void *buffer, size_t size
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LuaEngine::luaEngineQuit_p(lua_State *L_p)
|
||||||
|
{
|
||||||
|
int argumentCount = getArgumentCount(L_p);
|
||||||
|
if (argumentCount == 1) {
|
||||||
|
bool ok;
|
||||||
|
int retcode = getVariant(L_p, 1).toInt(&ok);
|
||||||
|
if (ok) {
|
||||||
|
QCoreApplication::exit(retcode);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QCoreApplication::quit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int LuaEngine::luaEngineVersion_p(lua_State *L_p)
|
int LuaEngine::luaEngineVersion_p(lua_State *L_p)
|
||||||
{
|
{
|
||||||
pushVariant(L_p, "0.1");
|
pushVariant(L_p, "0.1");
|
||||||
|
|
|
@ -76,6 +76,7 @@ public:
|
||||||
private:
|
private:
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
static int luaEngineWriter_p(lua_State *L_p, const void *buffer, size_t size, void *array);
|
static int luaEngineWriter_p(lua_State *L_p, const void *buffer, size_t size, void *array);
|
||||||
|
static int luaEngineQuit_p(lua_State *L_p);
|
||||||
static int luaEngineVersion_p(lua_State *L_p);
|
static int luaEngineVersion_p(lua_State *L_p);
|
||||||
static int luaEnginePlatform_p(lua_State *L_p);
|
static int luaEnginePlatform_p(lua_State *L_p);
|
||||||
static int luaObjectDelete_p(lua_State *L_p);
|
static int luaObjectDelete_p(lua_State *L_p);
|
||||||
|
|
|
@ -43,5 +43,6 @@ luaengineapp.depends += luaenginecore \
|
||||||
luaenginec.depends = luaenginecore
|
luaenginec.depends = luaenginecore
|
||||||
|
|
||||||
CONFIG(WITH_LUAENGINE_RUNTIME): SUBDIRS += luaengine
|
CONFIG(WITH_LUAENGINE_RUNTIME): SUBDIRS += luaengine
|
||||||
|
CONFIG(WITH_LUAENGINE_RUNTIME): SUBDIRS += luaenginecli
|
||||||
CONFIG(WITH_LUAENGINE_APPSTUB): SUBDIRS += luaengineapp
|
CONFIG(WITH_LUAENGINE_APPSTUB): SUBDIRS += luaengineapp
|
||||||
CONFIG(WITH_LUAENGINE_COMPILER): SUBDIRS += luaenginec
|
CONFIG(WITH_LUAENGINE_COMPILER): SUBDIRS += luaenginec
|
||||||
|
|
Loading…
Reference in a new issue