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

Function pushLuaErr

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

* @brief Pushes an early-failure {ok = false, error = msg[, errorCode]} table onto the Lua stack. */

Source from the content-addressed store, hash-verified

596 * @brief Pushes an early-failure {ok = false, error = msg[, errorCode]} table onto the Lua stack.
597 */
598static void pushLuaErr(lua_State* L, const QString& msg, const QString& code = QString())
599{
600 lua_createtable(L, 0, code.isEmpty() ? 2 : 3);
601 lua_pushboolean(L, 0);
602 lua_setfield(L, -2, "ok");
603
604 const QByteArray utf8 = msg.toUtf8();
605 lua_pushlstring(L, utf8.constData(), static_cast<size_t>(utf8.size()));
606 lua_setfield(L, -2, "error");
607
608 if (!code.isEmpty()) {
609 const QByteArray codeUtf8 = code.toUtf8();
610 lua_pushlstring(L, codeUtf8.constData(), static_cast<size_t>(codeUtf8.size()));
611 lua_setfield(L, -2, "errorCode");
612 }
613}
614
615/**
616 * @brief Lua C closure for apiCall(method, params?) returning a result table.

Callers 1

luaApiCallFunction · 0.85

Calls 6

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

Tested by

no test coverage detected