require

Name

require – Load a Lua module

Synopsis

result = require(module_name)

Description

If a module with the given name has not previously been loaded, then require(module_name) looks for a folder named module_name in the knights_data/server directory. The init.lua file within that directory is loaded and executed as a Lua chunk. The value returned from that chunk is returned from the require call, and also stored internally for future reference.

If a module with the given name has previously been loaded, then the stored return value from that module is just immediately returned from the require call, without loading the module or executing its init.lua code a second time.

Return Value

Whatever value was returned from the module's init.lua chunk becomes the return value from the require call.

Errors

If no module of the given name exists then an error is raised.

Also, if the loaded module itself throws any error, then that error is propagated by the require call.

Examples

To load the "classic" module, you would do the following:

local C = require("classic")

The C variable is now set to a table containing all the values exported from the classic module. For example, C.g_potion can be used to access the Graphic for the "potion" item.

See Also

dofile

module