Difference between revisions of "Require"

From GiderosMobile
m
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[(global)]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/(global)|(global)]]<br/>
 
  
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Loads and runs libraries. Roughly, [[Special:MyLanguage/require|require]] does the same job as [[Special:MyLanguage/dofile|dofile]], but, [[Special:MyLanguage/require|require]] searches for the file in a path. Because of that, [[Special:MyLanguage/require|require]] is the preferred function in Lua for loading libraries.</translate>
+
Loads and runs libraries.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
require(packagename)
 
require(packagename)
</source>
+
</syntaxhighlight>
  
=== <translate>Parameters</translate> ===
+
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.
'''packagename''': (string) <translate>library to load</translate> <br/>
+
 
 +
 
 +
'''Note''': you may need to "''exclude''" the required files from execution
 +
 
 +
=== Parameters ===
 +
'''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 ===
 +
'''[[Loading Order of Lua Files]]'''
  
 
{{(global)}}
 
{{(global)}}

Latest revision as of 00:23, 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