pub struct Chunk { /* private fields */ }Expand description
A not-yet-executed piece of Lua source.
Mirrors mlua::Chunk. Produced by Lua::load; finalized with
Chunk::exec, Chunk::eval, or Chunk::into_function.
Implementations§
Source§impl Chunk
impl Chunk
Sourcepub fn set_name(self, name: impl Into<String>) -> Self
pub fn set_name(self, name: impl Into<String>) -> Self
Override the chunk name shown in error messages / tracebacks.
Mirrors mlua::Chunk::set_name.
Sourcepub fn set_environment(self, env: Table) -> Self
pub fn set_environment(self, env: Table) -> Self
Set the environment (globals table) the loaded chunk runs in.
Mirrors mlua::Chunk::set_environment. Applied to the function produced
by Chunk::into_function / Chunk::exec / Chunk::eval.
Sourcepub fn set_compiler(self, compiler: Compiler) -> Self
pub fn set_compiler(self, compiler: Compiler) -> Self
Set the Compiler used to compile this chunk.
Mirrors mlua::Chunk::set_compiler.
Sourcepub fn call<R: FromLuaMulti>(self, args: impl IntoLuaMulti) -> Result<R>
pub fn call<R: FromLuaMulti>(self, args: impl IntoLuaMulti) -> Result<R>
Compile the chunk and call it with args, converting the result to R.
Mirrors mlua::Chunk::call.
Sourcepub fn set_mode(self, _mode: ChunkMode) -> Self
pub fn set_mode(self, _mode: ChunkMode) -> Self
The current chunk mode is always text here (luaur-rt loads source).
Mirrors mlua::Chunk::set_mode as a no-op accepting mlua::ChunkMode’s
role: luaur-rt auto-detects, so this is provided only for signature
parity and returns self unchanged.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The chunk name used for error messages / tracebacks.
Mirrors mlua::Chunk::name.
Sourcepub fn into_function(self) -> Result<Function>
pub fn into_function(self) -> Result<Function>
Load the compiled chunk and leave the resulting function on top of the
stack, returning a Function handle.
Mirrors mlua::Chunk::into_function.
Sourcepub fn exec(self) -> Result<()>
pub fn exec(self) -> Result<()>
Run the chunk for its side effects, discarding return values.
Mirrors mlua::Chunk::exec.
Sourcepub fn eval<R: FromLuaMulti>(self) -> Result<R>
pub fn eval<R: FromLuaMulti>(self) -> Result<R>
Run the chunk and convert its return value(s) to R.
Mirrors mlua::Chunk::eval. Like the Lua REPL (and mlua), the source is
first tried as an expression (by prepending return ); if that
compiles it is used, otherwise the chunk is run as a statement block.
This is what lets lua.load("coroutine.create(f)").eval::<Thread>() and
lua.load("function() ... end").eval::<Function>() work.