LSLua 0.3.1
by doy (doy at jjaro dot net)

Introduction
----------------------
LSLua is a scripting interface to LiteStep using the Lua scripting language.
Lua is a cross platform, open source, embeddable scripting language. This
module provides an interface to the LSAPI through Lua scripts.

To load LSLua, put a line resembling
*NetLoadModule lslua-0.3.1 load lslua.dll
in your theme.rc. The 'load lslua.dll' part is important, since, due to
restrictions in NetLoadModule, all of the packages that come with LSLua must
have a .dll extension for NetLoadModule to unpack them to the correct place.

Step.rc Settings and Bang Commands
----------------------
*LuaFile <filename>
Executes the given file. This registers any functions that are declared, and
executes any statements not declared in a function. Any function whose name
begins with "bang_" is also registered as a !bang command, named with the rest
of the function name. For example, the function bang_test would be registered
as !test. Bang functions take one optional string argument consisting of the
entire argument string passed to them.

*LuaPackageDir <directory>
Declares a directory to be added to the search path for Lua packages. Any
packages with the same name as an included package will be loaded instead of
the included package, to allow for reimplementations of the standard packages.

!LuaExec <lua chunk>
Executes the argument as a Lua chunk. Note that new bangs are not registered
using this method (this may change in the future).

Packages
----------------------
LSLua comes with five packages designed to make certain tasks easier. To use
them, include the line 'require "<packagename>";' at the top of your Lua
script. All functions provided by the packages are provided in a global table
with the same name as the package, so for example, you would access the pause()
function through timer.pause(). Here are some descriptions:

animation:
The animation package allows for interleaving animations. You can define
animation functions which define a sequence of frames, and then run them all
simultaneously.

Variables defined:
    create(): create takes a function as an argument, and returns a coroutine
    that can be passed to run()

    end_frame(): Use end_frame to signify the end of a frame in your animation
    function.

    run(): run takes an arbitrary number of animations created with create(),
    and interleaves them. It executes the first frame of the first animation,
    then the first frame of the second animation, all the way to the last
    frame, and it keeps going until all animations passed have had all of their
    frames run. After an animation is run, you must create() it again in order
    to run it again.

args:
The args package defines some useful argument parsing functions.

Variables defined:
    strjoin(): strjoin takes two arguments: a table of strings, and a string to
    use as the separator. It returns a string containing all of the elements of
    the table concatenated together, with elements separated by the separator
    string passed as the second argument.
    For example,
        strjoin( { "this", "is", "a", "test" }, " " ) == "this is a test"

    strsplit(): strsplit takes two arguments: a string, and a delimiter. It
    splits the string up into a table of substrings based on the delimiter, and
    returns that table.
    For example,
        strsplit( "this is a test", " " ) == { "this", "is", "a", "test" }

    qsplit(): qsplit takes between 4 arguments, some of them optional. The
    first argument is a string, the second is a table of strings to use as
    delimiters, and the third and fourth are tables of strings to use as left
    and right quotes, respectively. If the fourth argument is omitted, it
    defaults to the same as the third, and if they are both omitted, they
    default to { "\"", "'" }. If the second argument is omitted, it defaults
    to { " " }. If any of the second, third, or fourth arguments are strings,
    they are automatically converted to tables holding those strings. This
    function splits the string into substrings based on the delimiter like
    strsplit does, but it takes into account quote characters as well.
    For example,
        qsplit( "this is a 'string with quotes'" ) == { "this", "is", "a",
        "string with quotes" }
        qsplit( "%{hello},%{world}", ",", "%{", "}" ) == { "hello", "world" }
        qsplit( "[this is][a test]", "", "[", "]" ) == { "this is", "a test" }

    mstrsplit(): mstrsplit is the same as strsplit, except it returns the
    results as multiple return values rather than as a table.

    mqsplit(): mqsplit is the same as qsplit, except it returns the results
    as multiple return values rather than as a table.

evar:
The evar package contains a method to access LiteStep evars. This works
correctly for dynamic evars, but keep in mind that it will still produce an
error if you try to access a nonexistant evar. Neither saving evars (like
mzscript varfiles) nor setting them are supported yet, although they will be in
a future release.
Variables defined:
The evar table itself can be indexed to access the values of evars. For example,
evar.LiteStepDir == evar[ "LiteStepDir" ] == "C:\LiteStep\" (on my system).

thread:
The thread package doesn't provide anything useful to users of LSLua, but it
provides an important interface for package writers. It allows scripters to
access the global coroutines defined by LSLua each time a user defined bang is
called, allowing scripts to be started and resumed by name.
Variables defined:
    yield(): yield yields the current bang execution, with a value of a string
    that is passed to it as an argument. You must always pass an argument to
    yield, since LSLua interprets a yield with no arguments as the end of
    execution, and cleans up the running coroutine. If you declare your own
    coroutines in your code, you should always pass arguments back through
    coroutine.yield(), so that you can check to be sure that what is yielding
    is in fact your code, and not a thread trying to yield. See the animation
    package for an example of this.

    resume(): resume resumes the execution of the function that yielded with
    the name that is passed to resume.

timer:
The timer package is an interface to the timer LiteStep module, and allows for
pauses to work without freezing anything or stopping LSLua from functioning.
Variables defined:
    pause(): pause takes a single argument, defining how long to pause for,
    using the timer.dll syntax for time. For example, pause( 500 ) pauses for
    500 milliseconds, pause( "3s" ) pauses for 3 seconds, etc.

    resume(): resume is the function that timer.dll calls when the pause() is
    over. It shouldn't ever be called manually.

Other information
----------------------
LSLua defines the global variable LSLUA_VERSION, which is a string containing
the version of LSLua in major.minor.release form (i.e. "0.3.1"). During bang
execution, it also declares the global variable CURRENT_THREAD, which is the
coroutine that contains the bang execution. See the thread package for how
this can be used.

Information about Lua
----------------------
The Lua website is at http://lua.org. For information on Lua syntax, the Lua
manual is located at http://lua.org/manual/5.0/, and for information about
using the language, the site also hosts the book "Programming in Lua" at
http://lua.org/pil/. Code snippets and general information can be found at the
wiki, located at http://lua-users.org/wiki/. Finally, for more specific
questions not covered by those resources, feel free to ask for help in #lua on
irc.freenode.net.

Future
----------------------
- mzscript style varfile support. This will likely be added onto the evar
  package
- dynamically setting evars. This will definitely be added onto the evar
  package, through assignment to the 'evar' table
- A set of textedit replacement functions for text manipulation
- Better file manipulation functions (directory listings, etc)
- popen patch?

Known Bugs
----------------------
- message_box()s left open over a recycle will cause ls to crash, since when
  the function returns, the lua_State* that it was called from has already been
  deleted.
- Accessing nonexistant evars causes a litestep error, making it difficult to
  test evars that might not be defined. This error is generated from the
  VarExpansionEx() function itself, so I'm not sure how to fix it, other than
  reparsing the entire step.rc

Changelog
----------------------
0.3.1:
- the ls table in the evar package has been removed. Also, the toString(), etc
  functions are also removed, since they were only there for toBoolean(),
  which never worked correctly to begin with. Access evars with evar.EvarName.
- memory leak relating to coroutine creation fixed
- fixed random global in timer package, and changed how the names of the timers
  are generated
- reordered some arguments, changed some function names, and added mqsplit in
  the args package
- finally finished the documentation

0.3:
- lots of new require() stuff. All require()ed global variables are now
  namespaced, so use evar.LitestepDir or timer.pause().
  - require( "vars" ) is now require( "evar" ). Everything else is the same.
  - require( "args" ) has argument parsing functions
  - require( "timer" ) has helper functions for timer-0.5 (including pause())
  - require( "animation" ) is a method for easy concurrent animations
  - require( "thread" ) is a way to interact with the global coroutines
    created with each function call. It is used to implement timer.
- access the current lslua version from the global variable LSLUA_VERSION
- new step.rc setting: *LuaPackageDir for adding your own directories to the
  require() search path
- rewrote Lua.trigger() to use coroutines: manipulate them with the thread
  package
- runtime errors no longer disable lua
- !LuaExec to execute arbitrary lua code

0.2:
- First public release
- Bangs can now use arguments
- exec now has the option of passing several arguments in that will be passed
  as arguments to the command. For examples, see example.lua
- Removed pause(), since it really can't work correctly without better core
  support.
- Moved loading of evar code out to Lua as well... 'require( "vars" )' to get
  it.

Private alphas:
----------------------
0.1.1:
- Changed evar access to use the global 'ls' table. Access evars now like
  'ls.LiteStepDir:toString()'. Yes, the first is a period, and the second is a
  colon. In Lua, ls.var is equivalent to ls[ "var" ], and var:func is
  equivalent to var.func( self ) (self is lua's equivalent of 'this' in c++; it
  refers to the current object). Evar saving is coming shortly(:
- message_box now takes two arguments, first being the messagebox text, and the
  second being the title of the messagebox.
- The source zip now comes with just the precompiled Lua libraries. If you
  care, you can get the Lua source from http://lua.org/ftp/.

0.1:
- Initial release.
