| Lua package functions |
|---|
| Lua package functions These are the functions in the "package" table. The package manager is designed for scripters who need to use multiple files and load them in a consistent way. See also the "require" and "module" functions in the Lua base functions page. package.config This is a string containing the various character used by the package manager to handle loading packages: The default entries are: package.cpath This is a string containing the search path used for loading DLLs when using the "require" function. Default values are: In the above, the package name (eg. "socket") will replace the "?" characters and the current executable pathname (eg. "c:\mushclient") will replace the "!" characters. package.loaded A table of the packages that are already loaded. Built-in packages (eg. table, string) are also in this table. package.loaders This is a table of the loaders that Lua calls when handling the "require" function. As defined in the source code they are presently done in this order:
You could conceivable alter the behaviour of the "require" function be re-odering the loaders (eg. load DLLs before Lua code), deleting a loader, or adding your own. The existing loaders appear to push a string describing what files they failed to load (which you can see if you load a non-existant package), so any loaders you write yourself could return the loaded function on success, and an error string on failure. package.loadlib (libraryname, funcname) Loads the dynamic library (DLL), and tries to find the entrypoint named "funcname". On success returns the function funcname. On failure returns nil plus 2 error messages. The error might be "The specified module could not be found." if the DLL is not found. You may also get this message if the DLL is dependant on another DLL and that other DLL cannot be found. Use a "dependency checker" to see what DLLs the target DLL might require. If you are certain that the DLL you are requesting exists, then the problem is probably a dependency. The error might be "The specified procedure could not be found." if the function is not found in the DLL. You may also get this message if the DLL is dependant on another DLL and some entry points in that other DLL cannot be found. Use a "dependency checker" to see whether all required entry points have been resolved. If you are certain that the entry point that you are requesting exists in the target DLL, then the problem is probably a dependency from the target DLL to another DLL. You would normally then execute the function (as in the example below) to get it to install the Lua functions into the script space. Or, more briefly: package.path This is a string containing the search path used for loading Lua code when using the "require" function. Default values are: In the above, the package name (eg. "socket") will replace the "?" characters and the current executable pathname (eg. "c:\mushclient") will replace the "!" characters. package.preload A table of functions that can be used as loaders. If you want to make a special loader for your package you can insert it into the package.preload table. For example: In this example, when we required the package foo, the function was called. package.seeall (module) Sets a metatable for module with its __index field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function module. For example: The module code applies the function package.seeall to the new package (foo) and thus now package foo can access global variables. See Also ... Topics
Lua base functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua math functions
Lua os functions
Lua string functions
Lua table functions(Help topic: general=lua_package)
Documentation contents page |