EngineType handling improved and JSON array support

This commit is contained in:
Syping 2021-03-06 03:35:12 +01:00
parent 406905b359
commit 1fd16e168c
11 changed files with 102 additions and 56 deletions

View file

@ -26,8 +26,10 @@
int main(int argc, char *argv[])
{
#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
QApplication a(argc, argv);
#ifdef Q_OS_WIN
@ -50,7 +52,7 @@ int main(int argc, char *argv[])
QVariant scriptPath = arguments.first();
QFile luaScript(scriptPath.toString());
if (!luaScript.open(QIODevice::ReadOnly)) {
QTextStream(stderr) << "Error: Failed to open \"" << arguments.first().toString() << "\"." << endl;
QTextStream(stderr) << "Error: Failed to open \"" << arguments.first().toString() << "\"." << Qt::endl;
return 1;
}
@ -61,22 +63,29 @@ int main(int argc, char *argv[])
luaScript.reset();
}
LuaEngineGui luaEngineGui;
LuaEngineGui luaEngineGui(LuaEngine::RuntimeEngineType);
LuaEngineIO::pushClass(&luaEngineGui);
LuaEngineNetwork::pushClass(&luaEngineGui);
LuaEngineOS::pushClass(&luaEngineGui);
luaEngineGui.pushVariant("_LuaEngineRT", rtPath);
luaEngineGui.pushVariant("_LuaEngineMode", "GUI");
luaEngineGui.setProperty("EngineType", "Runtime");
luaEngineGui.setProperty("ScriptPath", scriptPath);
luaEngineGui.executeLuaScript(luaScript.readAll());
if (luaEngineGui.executeLuaFunction("main", arguments, true)) {
QVariant variant = luaEngineGui.returnVariant();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (variant.typeId() == QMetaType::Int || variant.typeId() == QMetaType::LongLong) {
#else
if (variant.type() == QVariant::Int || variant.type() == QVariant::LongLong) {
#endif
return variant.toInt();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
else if (variant.typeId() == QMetaType::QString) {
#else
else if (variant.type() == QVariant::String) {
#endif
if (variant.toString() == "GuiExecuted" || variant.toString() == "CliExecuted") {
return a.exec();
}

View file

@ -76,12 +76,11 @@ int main(int argc, char *argv[])
#endif
#endif
LuaEngineGui luaEngineGui;
LuaEngineGui luaEngineGui(LuaEngine::PortableEngineType);
LuaEngineIO::pushClass(&luaEngineGui);
LuaEngineNetwork::pushClass(&luaEngineGui);
LuaEngineOS::pushClass(&luaEngineGui);
luaEngineGui.pushVariant("_LuaEngineMode", "GUI");
luaEngineGui.setProperty("EngineType", "Portable");
luaEngineGui.executeLuaScript(luaScript);
QVariantList arguments;
@ -91,10 +90,18 @@ int main(int argc, char *argv[])
if (luaEngineGui.executeLuaFunction("main", arguments, true)) {
const QVariant variant = luaEngineGui.returnVariant();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (variant.typeId() == QMetaType::Int || variant.typeId() == QMetaType::LongLong) {
#else
if (variant.type() == QVariant::Int || variant.type() == QVariant::LongLong) {
#endif
return variant.toInt();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
else if (variant.typeId() == QMetaType::QString) {
#else
else if (variant.type() == QVariant::String) {
#endif
if (variant.toString() == "GuiExecuted" || variant.toString() == "CliExecuted") {
return a.exec();
}

View file

@ -47,7 +47,7 @@ int main(int argc, char *argv[])
QString outputFile;
const QStringList args = parser.positionalArguments();
if (args.length() < 1) {
QTextStream(stderr) << "Error: No input files." << endl;
QTextStream(stderr) << "Error: No input files." << Qt::endl;
return 1;
}
else {
@ -62,7 +62,7 @@ int main(int argc, char *argv[])
QFile luaScript(inputFile);
if (!luaScript.open(QIODevice::ReadOnly)) {
QTextStream(stderr) << "Error: Failed to open \"" << inputFile << "\"." << endl;
QTextStream(stderr) << "Error: Failed to open \"" << inputFile << "\"." << Qt::endl;
return 1;
}
@ -75,13 +75,13 @@ int main(int argc, char *argv[])
LuaEngine luaEngine;
if (!luaEngine.loadLuaScript(luaScript.readAll())) {
QTextStream(stderr) << "Error: Failed to load \"" << inputFile << "\"." << endl;
QTextStream(stderr) << "Error: Failed to load \"" << inputFile << "\"." << Qt::endl;
return 1;
}
QSaveFile outputSaveFile(outputFile);
if (!outputSaveFile.open(QIODevice::WriteOnly)) {
QTextStream(stderr) << "Error: Failed to open \"" << outputFile << "\"." << endl;
QTextStream(stderr) << "Error: Failed to open \"" << outputFile << "\"." << Qt::endl;
return 1;
}
@ -91,7 +91,7 @@ int main(int argc, char *argv[])
if (!portableLuaEngine.open(QIODevice::ReadOnly)) {
outputSaveFile.cancelWriting();
outputSaveFile.commit();
QTextStream(stderr) << "Error: Failed to open \"" << pLuaEngine << "\"." << endl;
QTextStream(stderr) << "Error: Failed to open \"" << pLuaEngine << "\"." << Qt::endl;
return 1;
}
outputSaveFile.write(portableLuaEngine.readAll());
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
if (lengthArray.size() > 8) {
outputSaveFile.cancelWriting();
outputSaveFile.commit();
QTextStream(stderr) << "Error: Lua Engine script is too large." << endl;
QTextStream(stderr) << "Error: Lua Engine script is too large." << Qt::endl;
return 1;
}
else {
@ -119,7 +119,7 @@ int main(int argc, char *argv[])
}
if (!outputSaveFile.commit()) {
QTextStream(stderr) << "Error: Failed to write \"" << args.at(1) << "\"." << endl;
QTextStream(stderr) << "Error: Failed to write \"" << args.at(1) << "\"." << Qt::endl;
return 1;
}

View file

@ -37,7 +37,7 @@ int main(int argc, char *argv[])
QVariant scriptPath = arguments.first();
QFile luaScript(scriptPath.toString());
if (!luaScript.open(QIODevice::ReadOnly)) {
QTextStream(stderr) << "Error: Failed to open \"" << arguments.first().toString() << "\"." << endl;
QTextStream(stderr) << "Error: Failed to open \"" << arguments.first().toString() << "\"." << Qt::endl;
return 1;
}
@ -48,22 +48,29 @@ int main(int argc, char *argv[])
luaScript.reset();
}
LuaEngine luaEngine;
LuaEngine luaEngine(LuaEngine::RuntimeEngineType);
LuaEngineIO::pushClass(&luaEngine);
LuaEngineNetwork::pushClass(&luaEngine);
LuaEngineOS::pushClass(&luaEngine);
luaEngine.pushVariant("_LuaEngineRT", rtPath);
luaEngine.pushVariant("_LuaEngineMode", "CLI");
luaEngine.setProperty("EngineType", "Runtime");
luaEngine.setProperty("ScriptPath", scriptPath);
luaEngine.executeLuaScript(luaScript.readAll());
if (luaEngine.executeLuaFunction("main", arguments, true)) {
QVariant variant = luaEngine.returnVariant();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (variant.typeId() == QMetaType::Int || variant.typeId() == QMetaType::LongLong) {
#else
if (variant.type() == QVariant::Int || variant.type() == QVariant::LongLong) {
#endif
return variant.toInt();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
else if (variant.typeId() == QMetaType::QString) {
#else
else if (variant.type() == QVariant::String) {
#endif
if (variant.toString() == "CliExecuted") {
return a.exec();
}

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2019 Syping
* Copyright (C) 2018-2021 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,8 +21,12 @@
#include <QCoreApplication>
#include <QTextStream>
#include <QMetaMethod>
LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
{
LuaEngine(LuaEngineType::UnknownEngineType, parent, loadBaseLibraries);
}
LuaEngine::LuaEngine(LuaEngineType engineType, QObject *parent, bool loadBaseLibraries) : QObject(parent), p_engineType(engineType)
{
L = luaL_newstate();
if (loadBaseLibraries)
@ -53,6 +57,11 @@ lua_State* LuaEngine::luaState()
return L;
}
LuaEngine::LuaEngineType LuaEngine::engineType()
{
return p_engineType;
}
void LuaEngine::loadBaseLibraries()
{
luaL_openlibs(L);
@ -148,7 +157,7 @@ bool LuaEngine::loadLuaScript(QIODevice *device, bool closeDevice)
bool LuaEngine::executeLuaScript(const QByteArray &data)
{
if (loadLuaScript(data))
return (lua_pcall(L, 0, LUA_MULTRET, 0) == 0) ? true : false;
return (lua_pcall(L, 0, LUA_MULTRET, 0) == 0);
return false;
}
@ -181,7 +190,7 @@ bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, bool requir
{
int returnCount = (requireReturn) ? LUA_MULTRET : 0;
lua_getglobal(L_p, name);
return (lua_pcall(L_p, 0, returnCount, 0) == 0) ? true : false;
return (lua_pcall(L_p, 0, returnCount, 0) == 0);
}
bool LuaEngine::executeLuaFunction(const char *name, const QVariant &argument, bool requireReturn)
@ -194,7 +203,7 @@ bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, const QVari
int returnCount = (requireReturn) ? LUA_MULTRET : 0;
lua_getglobal(L_p, name);
pushVariant(L_p, argument);
return (lua_pcall(L_p, 1, returnCount, 0) == 0) ? true : false;
return (lua_pcall(L_p, 1, returnCount, 0) == 0);
}
bool LuaEngine::executeLuaFunction(const char *name, const QVariantList &args, bool requireReturn)
@ -209,7 +218,7 @@ bool LuaEngine::executeLuaFunction(lua_State *L_p, const char *name, const QVari
for (const QVariant &argument : args) {
pushVariant(L_p, argument);
}
return (lua_pcall(L_p, args.count(), returnCount, 0) == 0) ? true : false;
return (lua_pcall(L_p, args.count(), returnCount, 0) == 0);
}
void LuaEngine::pushFunction(const char *name, lua_CFunction function)
@ -278,7 +287,7 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
QStringList stringList = variant.toStringList();
lua_createtable(L_p, 0, stringList.count());
int currentId = 1;
for (const QString &string : stringList) {
for (const QString &string : qAsConst(stringList)) {
lua_pushinteger(L_p, currentId);
lua_pushstring(L_p, string.toUtf8().data());
lua_settable(L_p, -3);
@ -289,7 +298,7 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
QVariantList variantList = variant.toList();
lua_createtable(L_p, 0, variantList.count());
int currentId = 1;
for (const QVariant &variant : variantList) {
for (const QVariant &variant : qAsConst(variantList)) {
lua_pushinteger(L_p, currentId);
pushVariant(L_p, variant);
lua_settable(L_p, -3);
@ -299,13 +308,10 @@ void LuaEngine::pushVariant(lua_State *L_p, const QVariant &variant)
else if ((QMetaType::Type)variant.type() == QMetaType::QVariantMap) {
QVariantMap variantMap = variant.toMap();
lua_createtable(L_p, 0, variantMap.count());
QVariantMap::const_iterator it = variantMap.constBegin();
QVariantMap::const_iterator end = variantMap.constEnd();
while (it != end) {
for (auto it = variantMap.constBegin(); it != variantMap.constEnd(); it++) {
lua_pushstring(L_p, it.key().toUtf8().data());
pushVariant(L_p, it.value());
lua_settable(L_p, -3);
it++;
}
}
else if ((QMetaType::Type)variant.type() == QMetaType::Void || (QMetaType::Type)variant.type() == QMetaType::VoidStar) {
@ -367,7 +373,7 @@ QVariant LuaEngine::getVariant(lua_State *L_p, int index)
else if (lua_isnoneornil(L_p, index)) {
return QVariant();
}
QTextStream(stderr) << "Warning: Didn't catch lua_isnoneornil before empty QVariant got returned" << endl;
QTextStream(stderr) << "Warning: Didn't catch lua_isnoneornil before empty QVariant got returned" << Qt::endl;
return QVariant();
}
@ -433,8 +439,7 @@ int LuaEngine::luaObjectDelete_p(lua_State *L_p)
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
switch (getVariant(L_p, 2).toInt())
{
switch (getVariant(L_p, 2).toInt()) {
case 1:
((QObject*)pointer)->deleteLater();
break;

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2019 Syping
* Copyright (C) 2018-2021 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,9 +33,12 @@ class LUAENGINESHARED_EXPORT LuaEngine : public QObject
{
Q_OBJECT
public:
enum LuaEngineType : qint8 { RuntimeEngineType = 0, PortableEngineType = 1, UnknownEngineType = -1 };
LuaEngine(QObject *parent = nullptr, bool loadBaseLibraries = true);
LuaEngine(LuaEngineType engineType, QObject *parent = nullptr, bool loadBaseLibraries = true);
~LuaEngine();
lua_State* luaState();
LuaEngineType engineType();
void loadBaseLibraries();
QByteArray dumpLuaScript();
bool loadLuaScript(const QByteArray &data);
@ -75,6 +78,7 @@ public:
private:
lua_State *L;
LuaEngineType p_engineType;
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);

View file

@ -1,6 +1,6 @@
#/*****************************************************************************
#* luaEngine Lua Engine for Qt
#* Copyright (C) 2018-2020 Syping
#* Copyright (C) 2018-2021 Syping
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2020 Syping
* Copyright (C) 2018-2021 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -54,8 +54,12 @@
LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries)
{
L = luaState();
pushClass(L);
pushClass(luaState());
}
LuaEngineGui::LuaEngineGui(LuaEngineType engineType, QObject *parent, bool loadBaseLibraries) : LuaEngine(engineType, parent, loadBaseLibraries)
{
pushClass(luaState());
}
void LuaEngineGui::pushClass(lua_State *L_p)
@ -223,7 +227,7 @@ int LuaEngineGui::updateUi(lua_State *L_p)
int LuaEngineGui::showFileDialog(lua_State *L_p)
{
QWidget *parent = nullptr;
QString dialogTitle = "LuaEngine";
QString dialogTitle = QStringLiteral("LuaEngine");
QString fileFormats = "All files (*)";
QFileDialog::FileMode fileMode = QFileDialog::ExistingFile;
QFileDialog::Options fileOptions;
@ -288,7 +292,7 @@ int LuaEngineGui::showMessageBox(lua_State *L_p)
if (getArgumentCount(L_p) >= 2) {
QWidget *parent = nullptr;
QString boxMessage = getVariant(L_p, 2).toString();
QString boxTitle = "LuaEngine";
QString boxTitle = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 3) {
boxTitle = getVariant(L_p, 3).toString();
if (getArgumentCount(L_p) >= 4) {
@ -912,7 +916,7 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString labelText = "LuaEngine";
QString labelText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
labelText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -932,7 +936,7 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
int LuaEngineGui::createDialog(lua_State *L_p)
{
QWidget *parent = nullptr;
QString windowTitle = "LuaEngine";
QString windowTitle = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
windowTitle = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -958,7 +962,7 @@ int LuaEngineGui::createGroupBox(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString groupBoxTitle = "LuaEngine";
QString groupBoxTitle = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
groupBoxTitle = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -979,7 +983,7 @@ int LuaEngineGui::createLabel(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString labelInput = "LuaEngine";
QString labelInput = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
labelInput = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1062,7 +1066,7 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString editText = "LuaEngine";
QString editText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1119,7 +1123,7 @@ int LuaEngineGui::createListView(lua_State *L_p)
int LuaEngineGui::createMainWindow(lua_State *L_p)
{
QWidget *parent = nullptr;
QString windowTitle = "LuaEngine";
QString windowTitle = QStringLiteral("LuaEngine");
bool centralWidget = true;
if (getArgumentCount(L_p) >= 1) {
windowTitle = getVariant(L_p, 1).toString();
@ -1134,6 +1138,9 @@ int LuaEngineGui::createMainWindow(lua_State *L_p)
}
}
QMainWindow *mainWindow = new QMainWindow(parent);
#if QT_VERSION >= 0x050900
mainWindow->setWindowFlag(Qt::WindowContextHelpButtonHint, false);
#endif
mainWindow->setObjectName(nameForPointer(mainWindow));
mainWindow->setWindowTitle(windowTitle);
if (centralWidget) {
@ -1238,7 +1245,7 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString editText = "LuaEngine";
QString editText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1288,7 +1295,7 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString buttonText = "LuaEngine";
QString buttonText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
buttonText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1309,7 +1316,7 @@ int LuaEngineGui::createRadioButton(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString labelText = "LuaEngine";
QString labelText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
labelText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1386,7 +1393,7 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
{
QLayout *layout = nullptr;
QWidget *parent = nullptr;
QString editText = "LuaEngine";
QString editText = QStringLiteral("LuaEngine");
if (getArgumentCount(L_p) >= 1) {
editText = getVariant(L_p, 1).toString();
if (getArgumentCount(L_p) >= 2) {
@ -1640,8 +1647,8 @@ QWidget* LuaEngineGui::windowForObject(QObject *object)
QString LuaEngineGui::pathForString(const QString &string, LuaEngine *engine)
{
if (QFileInfo(string).isRelative()) {
QString engineType = engine->property("EngineType").toString();
if (engineType == "Runtime") {
const LuaEngineType engineType = engine->engineType();
if (engineType == LuaEngineType::RuntimeEngineType) {
QString scriptPath = engine->property("ScriptPath").toString();
QString scriptDirPath = QFileInfo(scriptPath).canonicalPath();
QString newImagePath = QString("%1/%2").arg(scriptDirPath, string);

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2018-2020 Syping
* Copyright (C) 2018-2021 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ class LUAENGINEGUISHARED_EXPORT LuaEngineGui : public LuaEngine
Q_OBJECT
public:
LuaEngineGui(QObject *parent = nullptr, bool loadBaseLibraries = true);
LuaEngineGui(LuaEngineType engineType, QObject *parent = nullptr, bool loadBaseLibraries = true);
static void pushClass(lua_State *L_p);
static void pushClass(LuaEngine *luaEngine);
static int updateUi(lua_State *L_p);
@ -95,7 +96,6 @@ public:
static int getWidgetPixelRatio(lua_State *L_p);
private:
lua_State *L;
static QWidget* windowForObject(QObject *object);
static QString pathForString(const QString &string, LuaEngine *engine);
static void lpForPointer(void *pointer, QLayout **layout, QWidget **parent);

View file

@ -1,6 +1,6 @@
/*****************************************************************************
* luaEngine Lua Engine for Qt
* Copyright (C) 2019 Syping
* Copyright (C) 2019-2021 Syping
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -291,8 +291,15 @@ int LuaEngineIO::linkFile(lua_State *L_p)
int LuaEngineIO::jsonToTable(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
pushVariant(L_p, QJsonDocument::fromJson(getVariant(L_p, 1).toString().toUtf8()).object().toVariantMap());
return 1;
const QJsonDocument jsonDocument = QJsonDocument::fromJson(getVariant(L_p, 1).toString().toUtf8());
if (jsonDocument.isObject()) {
pushVariant(L_p, jsonDocument.object().toVariantMap());
return 1;
}
else if (jsonDocument.isArray()) {
pushVariant(L_p, jsonDocument.array().toVariantList());
return 1;
}
}
return 0;
}
@ -302,7 +309,7 @@ int LuaEngineIO::tableToJson(lua_State *L_p)
if (getArgumentCount(L_p) >= 1) {
QJsonDocument::JsonFormat jsonFormat = QJsonDocument::Compact;
if (getArgumentCount(L_p) >= 2) {
jsonFormat = (QJsonDocument::JsonFormat)getVariant(L_p, 2).toInt();
jsonFormat = static_cast<QJsonDocument::JsonFormat>(getVariant(L_p, 2).toInt());
}
pushVariant(L_p, QString::fromUtf8(QJsonDocument(QJsonObject::fromVariantMap(getVariant(L_p, 1).toMap())).toJson(jsonFormat)));
return 1;

View file

@ -1,6 +1,6 @@
#/*****************************************************************************
#* luaEngine Lua Engine for Qt
#* Copyright (C) 2019-2020 Syping
#* Copyright (C) 2019-2021 Syping
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.