Implementation notes

Posted by Nick Gammon on Wed 24 Nov 2004 09:02 AM — 1 posts, 7,722 views.

Australia Forum Administrator #0
All of the documented MUSHclient "world" functions are in the "world" table in the Lua interface. Note that the word "world" is a table, not a COM object. You can list all of the available functions like this:


for k in pairs (world) do print (k) end


This lists all functions exposed in the world table.

Note that in Lua function names are case-sensitive. That means that the "ColourNote" function is spelt "ColourNote" and not "colournote" nor "Colournote".

To make things easier, all world functions are also exposed as global functions, by using a metatable on the global table (the _G table).

Thus, you can do either:

world.Note ("hello")

or

Note ("hello")


Also, the "print" function, which is used extensively in the Lua tutorials, is linked to the "Note" function, so doing "print" in MUSHclient Lua is the same as Note.

To check the exact spelling of each function, look at:


http://www.gammon.com.au/scripts/function.php


or


http://www.gammon.com.au/scripts/doc.php


These list the meaning of all functions, and their exact spelling and capitalization.

Also, both pages list "Lua notes" which describe any differences in function behaviour under Lua.

Almost all functions behave the same under Lua as under other script languages, the notable exceptions being:

  • GetTrigger, GetAlias, GetTimer.

    These three functions returned data "by reference" which is not supported by Lua. Instead, they return their information as multiple function results. Read the documentation for more details.
  • Open.

    This function returns a COM object. This is not supported under Lua, so it returns nil instead.
  • Various functions have an optional last argument, which if omitted has various useful defaults. Read the documentation for more details.
  • Some functions have extended functionality if used in a different way. For example, GetVariableList returns a table of not only the variable names, but also their contents.