Skip to Content

console

Queue console commands, look up console variables and commands by name, and iterate the console registry.


pairs(console) does not iterate the console: LuaJIT here is built without Lua 5.2's __pairs. Use console.variables() / console.commands().

console.execute

console.execute(...)

Joins string and number arguments with spaces and queues the result in the game's command buffer. The command executes when the buffer is processed, normally on the next frame. string_cmd callbacks run before insertion. Empty text does nothing.

Returns: no values.

Errors: any argument is neither a string nor a number. Validation completes before any text is sent.

Command text: console.execute and string_cmd replacements do not quote, escape or filter text. Semicolons and line breaks separate commands; NUL terminates the text. Do not interpolate untrusted player names, chat messages or file contents without validation. For variable updates, prefer console.variable:set, which rejects text it cannot quote.

Console lookup

console.sensitivity
console['cl_righthand']

Looks up a console variable first, then a command. Development-only entries are hidden.

Returns: console.variable, console.command, or nil if neither exists. Each lookup creates a new object; cache the result when reusing it. execute, variables and commands are the namespace's own functions, so an engine entry with one of those names is reachable only through the iterators.

local sensitivity = console.sensitivity
if sensitivity then
    print(sensitivity:name(), sensitivity:get())
end
console.execute('echo', 'hello')

console.variables and console.commands

for name, variable in console.variables() do ... end
for name, command in console.commands() do ... end

Walk the game's console registry in its own order, one native step per iteration. Each step yields the name and the object console[name] returns for it: a console.variable from variables(), a console.command from commands(). A name that is both a variable and a command is yielded only by variables(), as lookup prefers the variable.

Development-only entries are hidden, as in lookup; a development-only entry flagged defensive is still reachable by name but is never listed. Nothing is copied up front: an entry registered during the loop is reached when the registry links it after the current position, and when the entry yielded last has been unregistered, the loop ends. Without the game's console interface both loops yield nothing.

local count = 0
for name in console.variables() do
    if name:find('^cl_') then count = count + 1 end
end
print(count, 'client variables')

On this page