Difference between revisions of "Require"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
m
Line 10: Line 10:
  
 
Roughly, '''require''' does the same job as [[dofile]] but '''require''' searches for the file in a path. Because of that, '''require''' is the preferred function in Lua for loading libraries.
 
Roughly, '''require''' does the same job as [[dofile]] but '''require''' searches for the file in a path. Because of that, '''require''' is the preferred function in Lua for loading libraries.
 +
 +
 +
'''Note''': you may need to "exclude" the required files from execution
  
 
=== Parameters ===
 
=== Parameters ===
 
'''packagename''': (string) library to load<br/>
 
'''packagename''': (string) library to load<br/>
 +
 +
=== Examples ===
 +
<syntaxhighlight lang="lua">
 +
local relpath = "losc/"
 +
local Types = require(relpath.."types")
 +
local Message = require(relpath.."message")
 +
local Timetag = require(relpath.."timetag")
 +
</syntaxhighlight>
  
 
=== See also ===
 
=== See also ===

Revision as of 00:22, 23 June 2024

Available since: Gideros 2011.6
Class: (global)

Description

Loads and runs libraries.

require(packagename)

Roughly, require does the same job as dofile but require searches for the file in a path. Because of that, require is the preferred function in Lua for loading libraries.


Note: you may need to "exclude" the required files from execution

Parameters

packagename: (string) library to load

Examples

local relpath = "losc/"
local Types = require(relpath.."types")
local Message = require(relpath.."message")
local Timetag = require(relpath.."timetag")

See also

Loading Order of Lua Files