Version 3.52 of MUSHclient introduces the Lua scripting language.
Unlike the other scripting languages so far, Lua is not implemented using COM (Micosoft's Component Object Model), but rather as a direct interface between MUSHclient and the Lua script language.
Lua is supplied as two DLLs as part of the MUSHclient download (lua.dll and lualib.dll).
The reasons for doing this are:
First taste of Lua scripting
Lua's syntax (which is based on Pascal) is very similar to VBscript and Jscript, so that if you are used to either of those, you should have no difficulty with Lua.
As an example, let's take a simple trigger script:
Match: * goes *
Name: test
Script: mytrigger
VBscript
Jscript
Lua
OK, Let's do the same thing in Lua ...
The syntax is very similar to the earlier examples. The major differences are:
Unlike the other scripting languages so far, Lua is not implemented using COM (Micosoft's Component Object Model), but rather as a direct interface between MUSHclient and the Lua script language.
Lua is supplied as two DLLs as part of the MUSHclient download (lua.dll and lualib.dll).
The reasons for doing this are:
- Lua is a nice, fast, compact scripting language, however with surprising power
- Since it is distributed with MUSHclient, script writers can assume that it is available (unlike, say, Perl or Python), without the end-user having to install extra languages.
- It allows scripting for platforms (notably Wine under Linux) that may not work properly using the COM interface
- The Lua language itself allows some very neat tricks which will be described in more posts in this section
- You can extend it by writing your own scripts in Lua (of course) but also by writing your own C DLLs and loading them into the program address space. For example, you might write custom windows or toolbars.
First taste of Lua scripting
Lua's syntax (which is based on Pascal) is very similar to VBscript and Jscript, so that if you are used to either of those, you should have no difficulty with Lua.
As an example, let's take a simple trigger script:
Match: * goes *
Name: test
Script: mytrigger
VBscript
sub mytrigger (name, line, wildcards)
world.Note "In trigger " & name
world.Send ("go " & wildcards (2)) ' follow him
world.Send ("kill " & wildcards (1)) ' attack him again
end sub
Jscript
function mytrigger (name, line, wildcardsVB)
{
wildcards = VBArray(wildcardsVB).toArray();
world.Note ("In trigger " + name)
world.Send ("go " + wildcards [1]) // follow him
world.Send ("kill " + wildcards [0]) // attack him again
} // end of mytrigger
Lua
OK, Let's do the same thing in Lua ...
function mytrigger (name, line, wildcards)
world.Note ("In trigger " .. name)
world.Send ("go " .. wildcards [2]) -- follow him
world.Send ("kill " .. wildcards [1]) -- attack him again
end
The syntax is very similar to the earlier examples. The major differences are:
- functions are defined with "function", not "sub"
- You concatenate strings with ".." rather than "+" or "&". This is a good thing, because Lua doesn't get confused when you try to add numbers (eg. "1" + "1" becomes 2, not 11).
- Comments are started with "--"