A Lua library is a file that returns a table. The function
require is used for loading libraries. It takes
as a string the leafname of the file and it returns the table.
When called, it first checks package.loaded to see if it has
already been loaded, and if it has it returns the table. If
it has not, it uses the string package.path to search for the
library. This string is a comma-separated list of templates , filepaths
each containing the symbol ? which is replaced by
the library's name. When RiscLua starts it reads the system
variable LUA_PATH5_4 for a default value for package.path,
which is set to rlua:lib.?,?.
Suppose you want to use your own libraries? Then you simply append
more templates to package.path. For example, if you
want to use a library called mylib which lives in the
same directory as your program, then start your program:
local path in package
local append = "%s,%s.mylib.?"
package.path = append (path, obey$dir ( ))
Note how the format string append can be used as a function.
The function obey$dir returns the directory containing
the file containing the program.