Struct mlua::Chunk [−][src]
#[must_use = "`Chunk`s do nothing unless one of `exec`, `eval`, `call`, or `into_function` are called on them"]pub struct Chunk<'lua, 'a> { /* fields omitted */ }
Expand description
Returned from Lua::load
and is used to finalize loading and executing Lua main chunks.
Implementations
impl<'lua, 'a> Chunk<'lua, 'a>
[src]
impl<'lua, 'a> Chunk<'lua, 'a>
[src]pub fn set_name<S: AsRef<[u8]> + ?Sized>(
self,
name: &S
) -> Result<Chunk<'lua, 'a>>
[src]
pub fn set_name<S: AsRef<[u8]> + ?Sized>(
self,
name: &S
) -> Result<Chunk<'lua, 'a>>
[src]Sets the name of this chunk, which results in more informative error traces.
pub fn set_environment<V: ToLua<'lua>>(self, env: V) -> Result<Chunk<'lua, 'a>>
[src]
pub fn set_environment<V: ToLua<'lua>>(self, env: V) -> Result<Chunk<'lua, 'a>>
[src]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.
pub fn set_mode(self, mode: ChunkMode) -> Chunk<'lua, 'a>
[src]
pub fn set_mode(self, mode: ChunkMode) -> Chunk<'lua, 'a>
[src]Sets whether the chunk is text or binary (autodetected by default).
Lua does not check the consistency of binary chunks, therefore this mode is allowed only
for instances created with Lua::unsafe_new
.
pub fn exec(self) -> Result<()>
[src]
pub fn exec(self) -> Result<()>
[src]Execute this chunk of code.
This is equivalent to calling the chunk function with no arguments and no return values.
pub fn exec_async<'fut>(self) -> LocalBoxFuture<'fut, Result<()>> where
'lua: 'fut,
[src]
This is supported on crate feature async
only.
pub fn exec_async<'fut>(self) -> LocalBoxFuture<'fut, Result<()>> where
'lua: 'fut,
[src]async
only.Asynchronously execute this chunk of code.
See Chunk::exec
for more details.
Requires feature = "async"
pub fn eval<R: FromLuaMulti<'lua>>(self) -> Result<R>
[src]
pub fn eval<R: FromLuaMulti<'lua>>(self) -> Result<R>
[src]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
.
pub fn eval_async<'fut, R>(self) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
R: FromLuaMulti<'lua> + 'fut,
[src]
This is supported on crate feature async
only.
pub fn eval_async<'fut, R>(self) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
R: FromLuaMulti<'lua> + 'fut,
[src]async
only.Asynchronously evaluate the chunk as either an expression or block.
See Chunk::eval
for more details.
Requires feature = "async"
pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(
self,
args: A
) -> Result<R>
[src]
pub fn call<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(
self,
args: A
) -> Result<R>
[src]Load the chunk function and call it with the given arguments.
This is equivalent to into_function
and calling the resulting function.
pub fn call_async<'fut, A, R>(self, args: A) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua> + 'fut,
[src]
This is supported on crate feature async
only.
pub fn call_async<'fut, A, R>(self, args: A) -> LocalBoxFuture<'fut, Result<R>> where
'lua: 'fut,
A: ToLuaMulti<'lua>,
R: FromLuaMulti<'lua> + 'fut,
[src]async
only.Load the chunk function and asynchronously call it with the given arguments.
See Chunk::call
for more details.
Requires feature = "async"
pub fn into_function(self) -> Result<Function<'lua>>
[src]
pub fn into_function(self) -> Result<Function<'lua>>
[src]Load this chunk into a regular Function
.
This simply compiles the chunk without actually executing it.