* @brief Pushes an early-failure {ok = false, error = msg[, errorCode]} table onto the Lua stack. */
| 596 | * @brief Pushes an early-failure {ok = false, error = msg[, errorCode]} table onto the Lua stack. |
| 597 | */ |
| 598 | static 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. |
no test coverage detected