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>
impl<'a> Context<'a>
Sourcepub fn push_number(&mut self, value: f64) -> LuaNumber
pub fn push_number(&mut self, value: f64) -> LuaNumber
Push a floating point number onto the stack.
Sourcepub fn push_string(&mut self, value: &str) -> LuaString
pub fn push_string(&mut self, value: &str) -> LuaString
Push a string onto the stack.
Sourcepub fn push_table(&mut self) -> LuaTable
pub fn push_table(&mut self) -> LuaTable
Create a new table and push it into the stack.
Sourcepub fn push_function(&mut self, func: Function) -> LuaFunction
pub fn push_function(&mut self, func: Function) -> LuaFunction
Push a C function onto the stack.
Sourcepub fn push_integer(&mut self, value: i64) -> LuaInteger
pub fn push_integer(&mut self, value: i64) -> LuaInteger
Push an integer onto the stack.
Sourcepub fn push_userdata<T>(&mut self, value: T) -> LuaUserdata
pub fn push_userdata<T>(&mut self, value: T) -> LuaUserdata
Push a user-defined value onto the stack.
Sourcepub fn push_userdata_named<T>(&mut self, value: T, name: &str) -> LuaUserdata
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.’
Sourcepub fn push_thread(&mut self) -> LuaThread
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.
Sourcepub fn create_lib(&mut self, lib: &[(&str, Function)]) -> LuaTable
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.,
Sourcepub fn push_global(&mut self, key: &str) -> LuaGeneric
pub fn push_global(&mut self, key: &str) -> LuaGeneric
Push a global value onto the stack.
Sourcepub fn set_global(&mut self, key: &str, value: &dyn ToLua)
pub fn set_global(&mut self, key: &str, value: &dyn ToLua)
Set a value in the global Lua namespace.
Sourcepub fn get_from_registry(&mut self, key: &dyn ToLua) -> LuaGeneric
pub fn get_from_registry(&mut self, key: &dyn ToLua) -> LuaGeneric
Get a value from the Lua registry.
Sourcepub fn get_from_registry_typed<T: FromLua>(
&mut self,
key: &dyn ToLua,
) -> Option<T>
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.
Sourcepub fn set_in_registry(&mut self, key: &dyn ToLua, value: &dyn ToLua)
pub fn set_in_registry(&mut self, key: &dyn ToLua, value: &dyn ToLua)
Set a value in the Lua registry.
Sourcepub fn get_arg(&mut self, arg: Index) -> Option<LuaGeneric>
pub fn get_arg(&mut self, arg: Index) -> Option<LuaGeneric>
Get an argument from this context.
Sourcepub fn get_arg_typed<T: FromLua>(&mut self, arg: Index) -> Option<T>
pub fn get_arg_typed<T: FromLua>(&mut self, arg: Index) -> Option<T>
Get an argument from this context.
Sourcepub fn get_arg_typed_or<T: FromLua>(
&mut self,
arg: Index,
value: T,
) -> Option<T>
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.
Sourcepub fn do_string(&mut self, s: &str) -> Result<()>
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.
Sourcepub fn push_context(&mut self) -> Context<'_>
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.
Sourcepub fn return_context(self, args: &[&dyn ToLua]) -> Index
pub fn return_context(self, args: &[&dyn ToLua]) -> Index
Returns a list of values to Lua.
Sourcepub fn metatable_register(&mut self, name: &str) -> (bool, LuaTable)
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.
Sourcepub fn metatable_get(&mut self, name: &str) -> Option<LuaTable>
pub fn metatable_get(&mut self, name: &str) -> Option<LuaTable>
Get a metatable from the registry.