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

Method parseLuaText

app/src/DataModel/Scripting/LuaScriptEngine.cpp:477–514  ·  view source on GitHub ↗

* @brief Shared driver: invokes the cached parse() over a raw byte buffer and converts the result. */

Source from the content-addressed store, hash-verified

475 * @brief Shared driver: invokes the cached parse() over a raw byte buffer and converts the result.
476 */
477QList<QStringList> DataModel::LuaScriptEngine::parseLuaText(const char* data, qsizetype len)
478{
479 Q_ASSERT(m_state != nullptr);
480 Q_ASSERT(data != nullptr);
481
482 if (!m_loaded || m_disabled)
483 return {};
484
485 try {
486 lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_parseRef);
487 lua_pushlstring(m_state, data, static_cast<size_t>(len));
488
489 m_deadline.setRemainingTime(kRuntimeWatchdogMs);
490 const int status = guardedPcall(m_state, 1, 1, 0);
491 m_deadline = QDeadlineTimer(QDeadlineTimer::Forever);
492
493 if (status != LUA_OK) [[unlikely]] {
494 const QString err = QString::fromUtf8(lua_tostring(m_state, -1));
495 lua_pop(m_state, 1);
496 qWarning() << "[LuaScriptEngine] Parse error:" << err;
497 if (err.contains(QLatin1String("timed out")))
498 (void)noteTimeoutAndCheckDisabled(0);
499
500 return {};
501 }
502
503 resetTimeoutCounter();
504 return convertResult();
505 } catch (const std::exception& e) {
506 qWarning() << "[LuaScriptEngine] parse uncaught exception:" << e.what();
507 } catch (...) {
508 qWarning() << "[LuaScriptEngine] parse uncaught non-std exception";
509 }
510
511 m_deadline = QDeadlineTimer(QDeadlineTimer::Forever);
512 lua_settop(m_state, 0);
513 return {};
514}
515
516/**
517 * @brief Runs the Lua parse function over a text frame (transcodes UTF-16 to UTF-8 bytes).

Callers

nothing calls this directly

Calls 5

lua_rawgetiFunction · 0.85
lua_pushlstringFunction · 0.85
guardedPcallFunction · 0.85
lua_settopFunction · 0.85
containsMethod · 0.45

Tested by

no test coverage detected