* @brief Converts the Lua value at @p idx into a QJsonValue; unsupported types become null. */
| 303 | * @brief Converts the Lua value at @p idx into a QJsonValue; unsupported types become null. |
| 304 | */ |
| 305 | static QJsonValue luaToJson(lua_State* L, int idx, int depth) |
| 306 | { |
| 307 | switch (lua_type(L, idx)) { |
| 308 | case LUA_TBOOLEAN: |
| 309 | return QJsonValue(lua_toboolean(L, idx) != 0); |
| 310 | case LUA_TNUMBER: { |
| 311 | if (lua_isinteger(L, idx)) |
| 312 | return QJsonValue(static_cast<qint64>(lua_tointeger(L, idx))); |
| 313 | |
| 314 | return QJsonValue(lua_tonumber(L, idx)); |
| 315 | } |
| 316 | case LUA_TSTRING: { |
| 317 | size_t len = 0; |
| 318 | const char* str = lua_tolstring(L, idx, &len); |
| 319 | return QJsonValue(QString::fromUtf8(str, static_cast<int>(len))); |
| 320 | } |
| 321 | case LUA_TTABLE: |
| 322 | return luaTableToJson(L, idx, depth); |
| 323 | case LUA_TNIL: |
| 324 | default: |
| 325 | return QJsonValue(); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | static void jsonValueToLua(lua_State* L, const QJsonValue& v, int depth); |
| 330 |
no test coverage detected