Skip to main content

load

Function load 

Source
pub fn load(
    chunk: any,
    chunkname: option<string>,
    mode: option<string>,
    env: option<any>,
) -> option<function>
Expand description

Loads a chunk. If chunk is a string, the chunk is that string; if it is a function, load calls it repeatedly to get the chunk pieces. If there are no syntactic errors, returns the compiled chunk as a function; otherwise, returns nil plus the error message.

chunkname is used in error messages and debug information; mode controls whether the chunk can be text or binary; env sets the first upvalue (_ENV) of the resulting function.

§Examples

local f = load("return 1 + 2")
print(f())                         --> 3
local bad, msg = load("return +")
print(bad, msg)                    --> nil   [string "return +"]:1: unexpected symbol