* @brief Installs a JS-style console table and replaces print() so script output is * visible in the application console instead of stdout. */
| 295 | * visible in the application console instead of stdout. |
| 296 | */ |
| 297 | void DataModel::installLuaConsole(lua_State* L) |
| 298 | { |
| 299 | Q_ASSERT(L != nullptr); |
| 300 | |
| 301 | static constexpr struct { |
| 302 | const char* name; |
| 303 | QtMsgType type; |
| 304 | } kLevels[] = { |
| 305 | { "log", QtDebugMsg}, |
| 306 | {"debug", QtDebugMsg}, |
| 307 | { "info", QtInfoMsg}, |
| 308 | { "warn", QtWarningMsg}, |
| 309 | {"error", QtCriticalMsg} |
| 310 | }; |
| 311 | |
| 312 | constexpr int kLevelCount = static_cast<int>(sizeof(kLevels) / sizeof(kLevels[0])); |
| 313 | |
| 314 | lua_createtable(L, 0, kLevelCount); |
| 315 | for (const auto& level : kLevels) { |
| 316 | lua_pushinteger(L, static_cast<lua_Integer>(level.type)); |
| 317 | lua_pushcclosure(L, luaConsoleLog, 1); |
| 318 | lua_setfield(L, -2, level.name); |
| 319 | } |
| 320 | |
| 321 | lua_setglobal(L, "console"); |
| 322 | |
| 323 | lua_pushinteger(L, static_cast<lua_Integer>(QtDebugMsg)); |
| 324 | lua_pushcclosure(L, luaConsoleLog, 1); |
| 325 | lua_setglobal(L, "print"); |
| 326 | } |
nothing calls this directly
no test coverage detected