* @brief Pushes a {ok, error?} table onto the Lua stack. */
| 41 | * @brief Pushes a {ok, error?} table onto the Lua stack. |
| 42 | */ |
| 43 | static void pushLuaResult(lua_State* L, bool ok, const QString& errorMsg) |
| 44 | { |
| 45 | lua_createtable(L, 0, ok ? 1 : 2); |
| 46 | |
| 47 | lua_pushboolean(L, ok ? 1 : 0); |
| 48 | lua_setfield(L, -2, "ok"); |
| 49 | |
| 50 | if (!ok) { |
| 51 | const QByteArray utf8 = errorMsg.toUtf8(); |
| 52 | lua_pushlstring(L, utf8.constData(), static_cast<size_t>(utf8.size())); |
| 53 | lua_setfield(L, -2, "error"); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @brief Builds a JS-style {ok, error?} map. |
no test coverage detected