Console (consoleNG)
In-game developer console with log filtering, command execution, and virtual scrolling.
In-game developer console with log filtering, command execution, and virtual scrolling.
Overview
ui_console provides a full-featured in-game console using ImGui. It displays game logs with level/origin filtering, supports GE Lua, TorqueScript, and CEF JS command execution, and includes virtual scrolling for performance.
Extension path: lua/ge/extensions/ui/console.lua
Dependencies: ui_imgui
Settings path: /settings/consoleNG.json
Exports (M)
| Function | Signature | Description |
|---|---|---|
show | () | Opens the console window. |
hide | () | Closes the console window. |
toggle | () | Toggles console visibility. |
onUpdate | (dtReal, dtSim, dtRaw) | Main render loop - processes logs, draws ImGui. |
onSerialize | () → data | Saves console state for hot-reload. |
onDeserialized | (data) | Restores console state after hot-reload. |
onExtensionLoaded | () | Hook - initializes console state on load. |
onFileChanged | (path) | Hook - responds to file changes. |
onVehicleDestroyed | (...) | Hook - refreshes vehicle combo list. |
onVehicleSwitched | (...) | Hook - refreshes vehicle combo list. |
onVehicleSpawned | (...) | Hook - refreshes vehicle combo list. |
onVehicleActiveChanged | (...) | Hook - refreshes vehicle combo list. |
Data Fields
| Field | Description |
|---|---|
M.dependencies | {"ui_imgui"} - required for ImGui rendering. |
M.onExtensionUnloaded | Cleanup callback assigned on the module table. |
M.inputCallback | Callback function for console input processing. |
Internals
Log Management
Logs are stored in a circular buffer (logs[] with logsHead/logsTail pointers), limited to ~1000 entries with 10% GC headroom:
if (logsTail - logsHead) > (logsLimit * 1.1) then
while logsHead < (logsTail - logsLimit) do
logs[logsHead] = nil
logsHead = logsHead + 1
end
endEach log entry: {timestamp, level, origin, message}.
Filtering
Two filter types:
- Level filter - Toggle D/I/W/E/A (Debug, Info, Warning, Error, All) via toolbar buttons
- Origin filter - Lua pattern matching against the origin field
Filters rerun on change, maintaining a logFiltered[] index array.
Command Execution
Three execution contexts via dropdown:
| Context | Method |
|---|---|
| GE Lua | executeLuaSandboxed(cmd) or Lua:queueLuaCommand(cmd) |
| TorqueScript | TorqueScript.eval(cmd) |
| CEF/UI JS | be:queueJS(cmd) |
| Vehicle Lua | vehicle:queueLuaCommand(cmd) |
Command history (20 entries) is persisted to /consoleHistory.json.
Virtual Scrolling
Uses ImGuiListClipper for efficient rendering of large log lists - only visible rows are drawn. Force auto-scroll keeps the view at the bottom for live log monitoring.
Settings
Persisted to /settings/consoleNG.json:
- Font size, background alpha, fullscreen mode
- Level filters, vehicle controls toggle
- History looping, sandbox mode, focus-on-show
Keyboard
- Backtick (`) - Closes console (via input callback character filter)
- Scroll Lock - Pauses log ingestion
- Up/Down arrows - Navigate command history
How It Works
toggle()or backtick key opens/closes the ImGui window- Game frame logs are ingested via
Engine.getFrameLog()each update - Logs are filtered by level and origin pattern, indexed for virtual scroll
- User types commands in the input field, executed in selected context
- Settings and history persist across sessions via JSON files
Additional Exports
The following exports are available but not yet documented in detail:
M.hideM.onConsoleLogM.onDeserializedM.onExtensionLoadedM.onFileChangedM.onSerializeM.onUpdateM.onVehicleActiveChangedM.onVehicleDestroyedM.onVehicleSpawnedM.onVehicleSwitchedM.showM.toggle