From 2879ae33edf53e353818c2c45d3c830e6793acf7 Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 16 May 2020 16:09:32 +0200 Subject: [PATCH] reworked executeProcess command --- src/luaengineos/luaengine/LuaEngineOS.cpp | 59 ++++++++++------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/luaengineos/luaengine/LuaEngineOS.cpp b/src/luaengineos/luaengine/LuaEngineOS.cpp index 7e2ead1..2ca5b7b 100644 --- a/src/luaengineos/luaengine/LuaEngineOS.cpp +++ b/src/luaengineos/luaengine/LuaEngineOS.cpp @@ -39,44 +39,35 @@ int LuaEngineOS::executeProcess(lua_State *L_p) bool runInBackground = false; bool processSuccessed = false; if (getArgumentCount(L_p) >= 2) { - QVariantList arguments = getArguments(L_p); - QVariant lastArgument = arguments.last(); - if (lastArgument.type() == QVariant::Bool) { - runInBackground = lastArgument.toBool(); - arguments.removeLast(); + QStringList processArguments; + QString processPath = getVariant(L_p, 1).toString(); + QVariant argument = getVariant(L_p, 2); + if ((QMetaType::Type)argument.type() == QMetaType::QVariantMap) { + QVariantMap argumentMap = argument.toMap(); + QVariantMap::const_iterator it = argumentMap.constBegin(); + QVariantMap::const_iterator end = argumentMap.constEnd(); + while (it != end) { + processArguments << it.value().toString(); + it++; + } } - if (arguments.length() >= 2) { - QStringList processArguments; - QString processPath = arguments.first().toString(); - arguments.removeFirst(); - for (const QVariant &argument : arguments) { - if ((QMetaType::Type)argument.type() == QMetaType::QVariantMap) { - QVariantMap argumentMap = argument.toMap(); - QVariantMap::const_iterator it = argumentMap.constBegin(); - QVariantMap::const_iterator end = argumentMap.constEnd(); - while (it != end) { - processArguments << it.value().toString(); - it++; - } - } - else { - processArguments << argument.toString(); - } - } - if (runInBackground) { - processSuccessed = QProcess::startDetached(processPath, processArguments); - } - else { - processReturn = QProcess::execute(processPath, processArguments); - } + else if (argument.type() == QVariant::Bool) { + runInBackground = argument.toBool(); } else { - if (runInBackground) { - processSuccessed = QProcess::startDetached(arguments.first().toString()); - } - else { - processReturn = QProcess::execute(arguments.first().toString()); + processArguments << argument.toString(); + } + if (getArgumentCount(L_p) >= 3) { + if (argument.type() == QVariant::Bool) { + processArguments << argument.toString(); } + runInBackground = getVariant(L_p, 3).toBool(); + } + if (runInBackground) { + processSuccessed = QProcess::startDetached(processPath, processArguments); + } + else { + processReturn = QProcess::execute(processPath, processArguments); } } else {