pub struct Chunk<'lua, 'a> { /* private fields */ }
Expand description

Returned from Lua::load and is used to finalize loading and executing Lua main chunks.

Implementations

Sets the name of this chunk, which results in more informative error traces.

Sets the first upvalue (_ENV) of the loaded chunk to the given value.

Lua main chunks always have exactly one upvalue, and this upvalue is used as the _ENV variable inside the chunk. By default this value is set to the global environment.

Calling this method changes the _ENV upvalue to the value provided, and variables inside the chunk will refer to the given environment rather than the global one.

All global variables (including the standard library!) are looked up in _ENV, so it may be necessary to populate the environment in order for scripts using custom environments to be useful.

Sets whether the chunk is text or binary (autodetected by default).

Be aware, Lua does not check the consistency of the code inside binary chunks. Running maliciously crafted bytecode can crash the interpreter.

Sets or overwrites a Luau compiler used for this chunk.

See Compiler for details and possible options.

Requires feature = "luau"

Execute this chunk of code.

This is equivalent to calling the chunk function with no arguments and no return values.

Asynchronously execute this chunk of code.

See exec for more details.

Requires feature = "async"

Evaluate the chunk as either an expression or block.

If the chunk can be parsed as an expression, this loads and executes the chunk and returns the value that it evaluates to. Otherwise, the chunk is interpreted as a block as normal, and this is equivalent to calling exec.

Asynchronously evaluate the chunk as either an expression or block.

See eval for more details.

Requires feature = "async"

Load the chunk function and call it with the given arguments.

This is equivalent to into_function and calling the resulting function.

Load the chunk function and asynchronously call it with the given arguments.

See call for more details.

Requires feature = "async"

Load this chunk into a regular Function.

This simply compiles the chunk without actually executing it.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.