mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2025-12-14 23:56:24 +01:00
EngineType handling improved and JSON array support
This commit is contained in:
parent
406905b359
commit
1fd16e168c
11 changed files with 102 additions and 56 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue