Struct Context

Source
pub struct Context<'a> { /* private fields */ }
Expand description

A wrapper around a Lua State.

Contains its own section of a Lua Stack; when the context goes out of scope, any value pushed using this context is popped.

Implementations§

Source§

impl<'a> Context<'a>

Source

pub fn new(state: &mut State) -> Context<'_>

Creates a new Context using an existing state.

Source

pub fn get_state(&mut self) -> &mut State

Get this context’s contained state.

Source

pub fn push_number(&mut self, value: f64) -> LuaNumber

Push a floating point number onto the stack.

Source

pub fn push_string(&mut self, value: &str) -> LuaString

Push a string onto the stack.

Source

pub fn push_table(&mut self) -> LuaTable

Create a new table and push it into the stack.

Source

pub fn push_bool(&mut self, value: bool) -> LuaBool

Push a boolean value onto the stack.

Source

pub fn push_function(&mut self, func: Function) -> LuaFunction

Push a C function onto the stack.

Source

pub fn push_integer(&mut self, value: i64) -> LuaInteger

Push an integer onto the stack.

Source

pub fn push_nil(&mut self) -> LuaNil

Push a nil value onto the stack.

Source

pub fn push_userdata<T>(&mut self, value: T) -> LuaUserdata

Push a user-defined value onto the stack.

Source

pub fn push_userdata_named<T>(&mut self, value: T, name: &str) -> LuaUserdata

Push a user-defined value onto the stack, and give it the metatable named ‘name.’

Source

pub fn push_thread(&mut self) -> LuaThread

Push a Lua thread onto the stack

You will need to do stuff with the Lua thread in a separate thread if you want two Lua threads to run concurrently, Lua doesn’t do any actual multithreading itself.

Source

pub fn create_lib(&mut self, lib: &[(&str, Function)]) -> LuaTable

Create a library using an array of Functions, and push the library table onto the stack.,

Source

pub fn push_global(&mut self, key: &str) -> LuaGeneric

Push a global value onto the stack.

Source

pub fn set_global(&mut self, key: &str, value: &dyn ToLua)

Set a value in the global Lua namespace.

Source

pub fn get_from_registry(&mut self, key: &dyn ToLua) -> LuaGeneric

Get a value from the Lua registry.

Source

pub fn get_from_registry_typed<T: FromLua>( &mut self, key: &dyn ToLua, ) -> Option<T>

Get a value from the Lua registry using a type.

Source

pub fn set_in_registry(&mut self, key: &dyn ToLua, value: &dyn ToLua)

Set a value in the Lua registry.

Source

pub fn get_arg(&mut self, arg: Index) -> Option<LuaGeneric>

Get an argument from this context.

Source

pub fn get_arg_typed<T: FromLua>(&mut self, arg: Index) -> Option<T>

Get an argument from this context.

Source

pub fn get_arg_typed_or<T: FromLua>( &mut self, arg: Index, value: T, ) -> Option<T>

Get an argument from this context.

If the argument does not exist, return a default value.

Source

pub fn do_string(&mut self, s: &str) -> Result<()>

Execute valid Lua code.

§Errors

Returns an error if the string is not valid Lua, or a runtime error occurs during execution.

Source

pub fn push_context(&mut self) -> Context<'_>

Push a new context on top of the current context.

New values can not be pushed onto the old context until the new context goes out of scope; however, values pushed by the old context can still be used by the new context.

Source

pub fn return_context(self, args: &[&dyn ToLua]) -> Index

Returns a list of values to Lua.

Source

pub fn metatable_register(&mut self, name: &str) -> (bool, LuaTable)

Register a new metatable in the registry.

Returns a tuple; the first value is if this metatable should be initialized, and the second value is the metatable itself.

Source

pub fn metatable_get(&mut self, name: &str) -> Option<LuaTable>

Get a metatable from the registry.

Source

pub fn metatable_register_named<T>( &mut self, lib: &[(&str, Function)], metamethods: &[(&str, Function)], unique_name: &str, ) -> Option<LuaTable>

Register a named metatable into the Lua registry.

Takes a list of member functions, a list of metamethods, and a unique name for this metatable.

Trait Implementations§

Source§

impl<'a> Drop for Context<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Context<'a>

§

impl<'a> RefUnwindSafe for Context<'a>

§

impl<'a> Send for Context<'a>

§

impl<'a> !Sync for Context<'a>

§

impl<'a> Unpin for Context<'a>

§

impl<'a> !UnwindSafe for Context<'a>

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, 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.