Loadfile: Difference between revisions

From GiderosMobile
m Text replacement - "<source" to "<syntaxhighlight"
No edit summary
 
(One intermediate revision by one other user not shown)
Line 7: Line 7:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
(function) = loadfile(filename)
(function) = loadfile(filename)
</source>
</syntaxhighlight>


If there are no errors, returns the compiled chunk as a function, otherwise returns nil plus the error message. The environment of the returned function is the global environment.
If there are no errors, returns the compiled chunk as a function, otherwise returns nil plus the error message. The environment of the returned function is the global environment.
Line 16: Line 16:
=== Return values ===
=== Return values ===
'''Returns''' (function) compiled chunk as a function, otherwise returns nil<br/>
'''Returns''' (function) compiled chunk as a function, otherwise returns nil<br/>
=== Example ===
'''You may need to exclude ''myfile.lua'' from execution'''
<syntaxhighlight lang="lua">
local level = loadfile("myfile.lua")()
</syntaxhighlight>


{{(global)}}
{{(global)}}

Latest revision as of 03:12, 2 December 2023

Available since: Gideros 2011.6
Class: (global)

Description

Loads a chunk from the file without execution.

(function) = loadfile(filename)

If there are no errors, returns the compiled chunk as a function, otherwise returns nil plus the error message. The environment of the returned function is the global environment.

Parameters

filename: (string) name of the file to load

Return values

Returns (function) compiled chunk as a function, otherwise returns nil

Example

You may need to exclude myfile.lua from execution

local level = loadfile("myfile.lua")()