WizardsOfLua¶
Provides the mod-wide settings and state that all spells share, including dynamic command management at runtime.
What a spell sets here applies to all spells, until the server restarts or /wol startup runs: then everything
goes back to its default value. To keep a setting, set it in a startup.lua script, which runs at server start and
with /wol startup.
The server's own settings, like how much of each game tick a spell may spend and which hosts spells can reach, are
files in config/wizards-of-lua/ that spells can't change: see Configuration.
Example: Send the output of log(...) to the server console, in a startup.lua
Fields¶
global: table — Read-Only¶
A shared table for cross-spell state during the current server runtime. The reference is read-only, but the table contents are mutable. Any spell can write to this table and any other spell can read the changes at any time. The table is cleared on server restart or when /wol startup runs.
loader: Loader — Read-Only¶
The mod loader this build of Wizards of Lua is made for. It decides which checks fire a PermissionCheckEvent. It names the build, not the server software: a hybrid server such as Arclight, or a bridge such as Sinytra Connector, can run it on top of other software.
log: LogTarget — Read/Write¶
Where the output of log(...) goes, for all spells. Default is "source".
version: string — Read-Only¶
The version of the installed Wizards of Lua mod.
Methods¶
listCommands() → list: CommandSpec[ ]¶
Lists all currently registered dynamic commands with their specs and code.
Returns their definitions, so you can iterate and display them in Lua.
Example
local all = WizardsOfLua.listCommands()
for i, cmd in ipairs(all) do
print(i, cmd.id, "→", cmd.pattern, "(level " .. cmd.level .. ")")
end
Returns
- list: CommandSpec[ ] — The definitions of all dynamic commands.
removeCommand(id: string) → success: boolean¶
Unregisters a previously registered dynamic command.
Removes the dynamic command with the given id that was added via WizardsOfLua.setCommand.
Example
local removed = WizardsOfLua.removeCommand("my.cmd")
if not removed then
print("No such dynamic command: my.cmd")
end
Parameters
- id: string — The id of the dynamic command to remove
Returns
- success: boolean —
trueif the command existed and was unregistered;falseotherwise
setCommand(command: CommandSpec)¶
Registers a new dynamic command, or replaces an existing dynamic command that has the same id.
Note: Dynamic commands are available only at the end of the current server tick. Yield one tick (e.g. sleep(1)) before invoking a newly registered command.
Example
WizardsOfLua.setCommand( {
id = "coins.add",
level = 0,
pattern = "coins add amount:%i to list:%players",
code = [[
for i,e in ipairs(args.list) do
local c = e.extra.coins or 0
c = c + args.amount
e:putExtra({coins=c})
print(e.name.." has now "..c.." coins.")
end
]]
})
Parameters
- command: CommandSpec — The definition of the command.