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

Method installLuaConsole

app/src/DataModel/Scripting/LuaCompat.cpp:297–326  ·  view source on GitHub ↗

* @brief Installs a JS-style console table and replaces print() so script output is * visible in the application console instead of stdout. */

Source from the content-addressed store, hash-verified

295 * visible in the application console instead of stdout.
296 */
297void 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}

Callers

nothing calls this directly

Calls 5

lua_createtableFunction · 0.85
lua_pushintegerFunction · 0.85
lua_pushcclosureFunction · 0.85
lua_setfieldFunction · 0.85
lua_setglobalFunction · 0.85

Tested by

no test coverage detected