MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaToJson

Function luaToJson

app/src/DataModel/Scripting/ScriptApiCall.cpp:305–327  ·  view source on GitHub ↗

* @brief Converts the Lua value at @p idx into a QJsonValue; unsupported types become null. */

Source from the content-addressed store, hash-verified

303 * @brief Converts the Lua value at @p idx into a QJsonValue; unsupported types become null.
304 */
305static 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
329static void jsonValueToLua(lua_State* L, const QJsonValue& v, int depth);
330

Callers 1

luaTableToJsonFunction · 0.85

Calls 5

lua_typeFunction · 0.85
lua_tobooleanFunction · 0.85
lua_isintegerFunction · 0.85
lua_tolstringFunction · 0.85
luaTableToJsonFunction · 0.85

Tested by

no test coverage detected