module()

Type Function
Library package
Return value none
Revision 2017.3060
Keywords module
See also require()
package.loaded
Alert

This function has been deprecated and should not be used.

Overview

Creates a module. If there is a table in package.loaded[name], this table is the module. Otherwise creates a new table t and sets it as the value of the global name and the value of package.loaded[name]. This function also initializes t._NAME with the given name, t._M with the module (t itself), and t._PACKAGE with the package name (the full module name minus last component; see below). Finally, module() sets t as the new environment of the current function and the new value of package.loaded[name], so that require returns t.

If name is a compound name (that is, one with components separated by dots), module() creates (or reuses, if they already exist) tables for each component. For instance, if name is a.b.c, then module() stores the module table in field c of field b of global a.

This function can receive optional options after the module name, where each option is a function to be applied over the module.

Naming Restrictions

Forbidden Characters

Module file can't have any . characters in the file name (except for the .lua extension). This change was made to allow Lua files in subdirectories on iOS.

Syntax

module( name [, ...] )
name (required)

String. The name of the module.