* @brief Shared driver: invokes the cached parse() over a raw byte buffer and converts the result. */
| 475 | * @brief Shared driver: invokes the cached parse() over a raw byte buffer and converts the result. |
| 476 | */ |
| 477 | QList<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). |
nothing calls this directly
no test coverage detected