loadfile

Loads a Lua file and parses it

Prototype

f, err = loadfile (filename)

Description

Opens the named file, parses it and returns the compiled chunk as a function. Does not execute it.

f = assert (loadfile ("myfile.lua"))
f () -- execute function now
Compare to dofile, which executes it as well. That is, dofile is equivalent to the two lines of code above.

If there is an error in the loading process, for example the file is not found, or it is found but has a syntax error, then f will be nil and err will be the nature of the error.

Lua functions

Topics