Global Functions¶
These functions and variables are available in every Wizards of Lua script without any require.
log(value: any, ...: any)¶
The log(...) function behaves like Lua's built-in print(...), but its output is controlled by the WizardsOfLua.log setting.
This allows consistent debugging output even when command feedback is globally suppressed.
See WizardsOfLua.log for details on how to configure the output target.
Example
Parameters
| Name | Type | Description |
|---|---|---|
value |
any |
The first value to log. |
... |
any |
Additional values to log, all will be converted to strings and space-separated. |
str(obj: any) → A: string¶
Converts the given object into a string representation.
This is a simplified alias for inspect(obj, { metatables = false }), omitting metatables for cleaner output.
Example
Parameters
| Name | Type | Description |
|---|---|---|
obj |
any |
The object to convert. |
Returns
string— A string representation of the object.
inspect(value: any, options: table|nil) → A: string¶
Converts the given Lua value into a human-readable string representation.
This function is especially useful for printing or logging deeply nested tables, such as configurations, game state, or debug info.
It safely handles cyclic references, shared references, metatables, and offers advanced formatting via the process callback.
Example
local t = { foo = "bar", list = {1, 2, 3} }
print(inspect(t)) -- => { foo = "bar", list = { 1, 2, 3 } }
Options
-
depth(number): Maximum depth to recurse into nested tables. Default:math.huge. -
newline(string): Line separator used in output. Default:"\n". -
indent(string): Indentation string per level. Default:" "(two spaces). -
metatables(boolean): Whether to include metatables. Default:true. -
process(fun(value: any, path: table): any): Callback to transform values before they’re printed. Receives the value and its path in the table.
Example with Options
local t = { player = { name = "Steve", score = 42 } }
print(inspect(t, {
depth = 1,
indent = "\t",
metatables = false
}))
Example with process Option
print(inspect(gameData, {
process = function(value, path)
if type(value) == "string" and #value > 50 then
return "<string truncated>"
end
return value
end
}))
Parameters
| Name | Type | Description |
|---|---|---|
value |
any |
The Lua value to inspect (usually a table, but can be any type). |
options |
table|nil |
Optional formatting options (see above). |
Returns
string— A formatted string representing the structure and content of the value.
sleep(ticks: number)¶
Pauses this program's execution for a specified number of game ticks.
Example
Parameters
| Name | Type | Description |
|---|---|---|
ticks |
number |
The number of game ticks to pause for. |
declare(name: string, superclass_metatable: table|nil) → The: table¶
Declares a new class type with the given name.
This function creates a new class metatable, optionally inheriting from a superclass metatable.
Example
Parameters
| Name | Type | Description |
|---|---|---|
name |
string |
The name of the class to declare. |
superclass_metatable |
table|nil |
The metatable of the superclass, or nil for a base class. |
Returns
table— The metatable for the newly declared class.
instanceOf(class_metatable: table, object: table) → boolean¶
Checks whether the given object is an instance of the specified class.
This performs a recursive check using metatable inheritance.
Example
Parameters
| Name | Type | Description |
|---|---|---|
class_metatable |
table |
The metatable of the class to check against. |
object |
table |
The object to check. |
Returns
boolean—trueif the object is an instance of the class,falseotherwise.