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

Function pushLuaResult

app/src/DataModel/Scripting/DeviceWriteApi.cpp:79–91  ·  view source on GitHub ↗

* @brief Pushes a {ok, error?} table onto the Lua stack. */

Source from the content-addressed store, hash-verified

77 * @brief Pushes a {ok, error?} table onto the Lua stack.
78 */
79static void pushLuaResult(lua_State* L, bool ok, const QString& errorMsg)
80{
81 lua_createtable(L, 0, ok ? 1 : 2);
82
83 lua_pushboolean(L, ok ? 1 : 0);
84 lua_setfield(L, -2, "ok");
85
86 if (!ok) {
87 const QByteArray utf8 = errorMsg.toUtf8();
88 lua_pushlstring(L, utf8.constData(), static_cast<size_t>(utf8.size()));
89 lua_setfield(L, -2, "error");
90 }
91}
92
93/**
94 * @brief Lua C closure for deviceWrite(data, sourceId?) returning a result table.

Callers 2

luaDeviceWriteFunction · 0.70
luaActionFireFunction · 0.70

Calls 5

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

Tested by

no test coverage detected