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
sourceimpl<'lua, 'a> Chunk<'lua, 'a>
impl<'lua, 'a> Chunk<'lua, 'a>
sourcepub fn set_name(self, name: impl AsRef<str>) -> Result<Chunk<'lua, 'a>, Error>
pub fn set_name(self, name: impl AsRef<str>) -> Result<Chunk<'lua, 'a>, Error>
Sets the name of this chunk, which results in more informative error traces.
sourcepub fn set_environment<V>(self, env: V) -> Result<Chunk<'lua, 'a>, Error>where
V: ToLua<'lua>,
pub fn set_environment<V>(self, env: V) -> Result<Chunk<'lua, 'a>, Error>where
V: ToLua<'lua>,
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.
sourcepub fn set_mode(self, mode: ChunkMode) -> Chunk<'lua, 'a>
pub fn set_mode(self, mode: ChunkMode) -> Chunk<'lua, 'a>
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.
sourcepub fn set_compiler(self, compiler: Compiler) -> Chunk<'lua, 'a>
pub fn set_compiler(self, compiler: Compiler) -> Chunk<'lua, 'a>
Sets or overwrites a Luau compiler used for this chunk.
See Compiler
for details and possible options.
Requires feature = "luau"
sourcepub fn exec(self) -> Result<(), Error>
pub fn exec(self) -> Result<(), Error>
Execute this chunk of code.
This is equivalent to calling the chunk function with no arguments and no return values.
sourcepub fn exec_async<'fut>(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'fut, Global>>where
'lua: 'fut,
pub fn exec_async<'fut>(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'fut, Global>>where
'lua: 'fut,
sourcepub fn eval<R>(self) -> Result<R, Error>where
R: FromLuaMulti<'lua>,
pub fn eval<R>(self) -> Result<R, Error>where
R: FromLuaMulti<'lua>,
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
.
sourcepub fn eval_async<'fut, R>(
self
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + 'fut, Global>>where
'lua: 'fut,
R: 'fut + FromLuaMulti<'lua>,
pub fn eval_async<'fut, R>(
self
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + 'fut, Global>>where
'lua: 'fut,
R: 'fut + FromLuaMulti<'lua>,
Asynchronously evaluate the chunk as either an expression or block.
See eval
for more details.
Requires feature = "async"
sourcepub fn call<A, R>(self, args: A) -> Result<R, Error>where
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua>,
pub fn call<A, R>(self, args: A) -> Result<R, Error>where
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua>,
Load the chunk function and call it with the given arguments.
This is equivalent to into_function
and calling the resulting function.
sourcepub fn call_async<'fut, A, R>(
self,
args: A
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + 'fut, Global>>where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: 'fut + FromLuaMulti<'lua>,
pub fn call_async<'fut, A, R>(
self,
args: A
) -> Pin<Box<dyn Future<Output = Result<R, Error>> + 'fut, Global>>where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: 'fut + FromLuaMulti<'lua>,
Load the chunk function and asynchronously call it with the given arguments.
See call
for more details.
Requires feature = "async"
sourcepub fn into_function(self) -> Result<Function<'lua>, Error>
pub fn into_function(self) -> Result<Function<'lua>, Error>
Load this chunk into a regular Function
.
This simply compiles the chunk without actually executing it.