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

Function jsonValueToLua

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

* @brief Pushes any QJsonValue onto the Lua stack; null becomes nil. */

Source from the content-addressed store, hash-verified

385 * @brief Pushes any QJsonValue onto the Lua stack; null becomes nil.
386 */
387static void jsonValueToLua(lua_State* L, const QJsonValue& v, int depth)
388{
389 switch (v.type()) {
390 case QJsonValue::Bool:
391 lua_pushboolean(L, v.toBool() ? 1 : 0);
392 break;
393 case QJsonValue::Double:
394 pushJsonNumber(L, SerialStudio::toDouble(v));
395 break;
396 case QJsonValue::String: {
397 const QByteArray s = v.toString().toUtf8();
398 lua_pushlstring(L, s.constData(), static_cast<size_t>(s.size()));
399 break;
400 }
401 case QJsonValue::Array:
402 jsonArrayToLua(L, v.toArray(), depth);
403 break;
404 case QJsonValue::Object:
405 jsonObjectToLua(L, v.toObject(), depth);
406 break;
407 case QJsonValue::Null:
408 case QJsonValue::Undefined:
409 default:
410 lua_pushnil(L);
411 break;
412 }
413}
414
415//--------------------------------------------------------------------------------------------------
416// Shared dispatcher

Callers 2

jsonObjectToLuaFunction · 0.85
jsonArrayToLuaFunction · 0.85

Calls 8

lua_pushbooleanFunction · 0.85
pushJsonNumberFunction · 0.85
lua_pushlstringFunction · 0.85
jsonArrayToLuaFunction · 0.85
jsonObjectToLuaFunction · 0.85
lua_pushnilFunction · 0.85
typeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected