MudWalker Scripting

MudWalker currently offers Lua as an embedded language for scripts in triggers, etc.

Script Languages

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):

Literal Text
Returns or sends exactly the text you enter in the script field.
Lua
Lua source code. See below for details on the Lua interface.
Lua (in substitution)
Lua source code embedded in plain text. Deliberately imitative of Rapscallion's script language.

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

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.

Aliases

The complete typed line is at numeric key 0, and the line without the alias name is 1.

Lua Usage

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

Lua Details

Builtin Functions

MudWalker makes the following builtin functions available in the Lua namespace:

Builtin Methods

The following methods are callable on applicable objects:

:config()
Objective-C config. Usually used on arg.linkable, where it returns the configuration object the trigger filter is using.
:link_send(obj, linkName)
Objective-C send:toLinkFor:. Usually used on arg.linkable.
:objectAtPath(path)
Objective-C 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.)

Convenience Functions

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")