MudWalker currently offers Lua as an embedded language for scripts in triggers, etc.
Anywhere you can enter a script in MudWalker, there will be a choice of script languages. The following languages are provided with MudWalker (others may be added by plugins):
Lines starting with @@
are treated as Lua code. Other lines become send('...')
statements, where ...
is the text of the line. Lua expressions may be inserted in such lines by the syntaxes $$expr
or $(expr)$
. $$
expressions end at the first space character.
Triggers pass the strings captured by parentheses in the match pattern to the script in numeric keys 1
..n
, and the complete matched line as 0
. The trigger filter itself is passed in as linkable
.
The complete typed line is at numeric key 0
, and the line without the alias name is 1
.
See the documentation at www.lua.org for information on the Lua language itself.
Short description: send(str)
to send a line to the server, message(str)
to send a line to your terminal.
Arguments for the script are available in the 'arg' table.
Example:
local who = arg[1] if who ~= "Jerk" then message("Greeting " .. who) send("say Hi, " .. who .. "!") end
The same example, but using the substitution syntax:
@@local who = arg[1] @@if who ~= "Jerk" then @@message("Greeting " .. who) say Hi, $(who)$! @@end
MudWalker makes the following builtin functions available in the Lua namespace:
string
, table
, and math
libraries
base
library except:
print
loadfile
dofile
loadstring
require
print(str)
- print a message to the script debug window.
new_lineString(str[, role])
- creates a MWLineString object.
configPath(str, str, ...)
- returns a MWConfigPath object with the specified components.
soundNamed(name)
- returns a system sound, e.g. soundNamed('Sosumi')
.speak(text[, voice-name])
- speak the text.
The following methods are callable on applicable objects:
:config()
config
. Usually used on arg.linkable
, where it returns the configuration object the trigger filter is using.:link_send(obj, linkName)
send:toLinkFor:
. Usually used on arg.linkable
.:objectAtPath(path)
objectAtPath:
. Usually used on arg.linkable:config()
, where it returns the value for the given configuration path.(To be written: explanations of what MWLineString and MWConfigPath are.)
Also, the file mw_init.lua
inside the Lua plugin in the MudWalker application package is executed when a new Lua interpreter is set up. It defines useful functions based on the primitives above:
send(obj[, link])
Sends obj inward
(to your terminal window) or outward
(to the server), depending on link (which defaults to "outward").
If obj is a string, converts it to a MWLineString.
message(str)
Sends a message to your terminal, marked as being such (rather than text from the server). Exactly equivalent to:
arg.linkable:link_send(new_lineString(str, "MWLocalRole"), "inward")
playSound(name)
Plays the named system sound. Exactly equivalent to:
arg.linkable:link_send(soundNamed(name), "inward")