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

Function pushApiResult

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

* @brief Pushes the CommandResponse onto the Lua stack as a result table. */

Source from the content-addressed store, hash-verified

565 * @brief Pushes the CommandResponse onto the Lua stack as a result table.
566 */
567static void pushApiResult(lua_State* L, const API::CommandResponse& r)
568{
569 lua_createtable(L, 0, r.success ? 2 : 4);
570
571 lua_pushboolean(L, r.success ? 1 : 0);
572 lua_setfield(L, -2, "ok");
573
574 if (r.success) {
575 if (!r.result.isEmpty()) {
576 jsonObjectToLua(L, r.result, 0);
577 lua_setfield(L, -2, "result");
578 }
579 } else {
580 const QByteArray msg = r.errorMessage.toUtf8();
581 lua_pushlstring(L, msg.constData(), static_cast<size_t>(msg.size()));
582 lua_setfield(L, -2, "error");
583
584 const QByteArray code = r.errorCode.toUtf8();
585 lua_pushlstring(L, code.constData(), static_cast<size_t>(code.size()));
586 lua_setfield(L, -2, "errorCode");
587
588 if (!r.errorData.isEmpty()) {
589 jsonObjectToLua(L, r.errorData, 0);
590 lua_setfield(L, -2, "errorData");
591 }
592 }
593}
594
595/**
596 * @brief Pushes an early-failure {ok = false, error = msg[, errorCode]} table onto the Lua stack.

Callers 1

luaApiCallFunction · 0.85

Calls 7

lua_createtableFunction · 0.85
lua_pushbooleanFunction · 0.85
lua_setfieldFunction · 0.85
jsonObjectToLuaFunction · 0.85
lua_pushlstringFunction · 0.85
isEmptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected