Skip to main content

Chunk

Struct Chunk 

Source
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

Source

pub fn set_name(self, name: impl Into<String>) -> Self

Override the chunk name shown in error messages / tracebacks.

Mirrors mlua::Chunk::set_name.

Source

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.

Source

pub fn set_compiler(self, compiler: Compiler) -> Self

Set the Compiler used to compile this chunk. Mirrors mlua::Chunk::set_compiler.

Source

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.

Source

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.

Source

pub fn name(&self) -> &str

The chunk name used for error messages / tracebacks.

Mirrors mlua::Chunk::name.

Source

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.

Source

pub fn exec(self) -> Result<()>

Run the chunk for its side effects, discarding return values.

Mirrors mlua::Chunk::exec.

Source

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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Chunk

§

impl !Send for Chunk

§

impl !Sync for Chunk

§

impl !UnwindSafe for Chunk

§

impl Freeze for Chunk

§

impl Unpin for Chunk

§

impl UnsafeUnpin for Chunk

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> MaybeSend for T

Source§

impl<T> MaybeSync for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.