Prev: Next: Up: Lua[Contents][Index]


8.1 Global Lua Configuration

Lua sources are loaded from the global Lua section, using two statements: Load and LoadGlobal. These take as argument the name of a Lua source file to parse and load. As usual, relative pathnames are looked up in the include directory.

The Load statement loads the file to per-thread Lua interpreters, while LoadGlobal loads it to the global one. Example usage:

Lua
    Load "auth-bearer.lua"
End

If the file ends with a return statement, it is loaded as in Lua require. The return value is then available in Lua global variable whose name is obtained from the filename using the following procedure:

  1. Remove the ‘.lua’ suffix.
  2. Unless first character is a letter of latin alphabet or underscore, add underscore at the beginning.
  3. In the resulting string, replace each character other than letter, digit or underscore with an underscore.

Thus, if the file auth-bearer.lua ends with a return, the returned value will be available in Lua as auth_bearer.

You can also supply variable name explicitly, as second argument, e.g.:

Lua
    Load "auth-bearer.lua" "bearer"
End

Of course, you can use as many Load (or LoadGlobal) statements as there are files you wish to load.

This section can also be used to modify Lua search paths. Two statements are provided for this purpose: Path modifies search path for Lua source files (package.path), and CPath modifies search path for dynamic libraries (package.cpath). Both statements add their argument at the beginning of the corresponding package path. For example:

Lua
    Path "/usr/share/pound/?.lua"
    Load "auth-bearer.lua" "bearer"
End

Notice that Path statement has no effect on where Load looks for its argument (it always uses pound include path to locate relative file names). Instead, it affects require statements in loaded Lua sources.


Prev: Next: Up: Lua[Contents][Index]