Struct rlua::Lua
[−]
[src]
pub struct Lua { /* fields omitted */ }
Top level Lua struct which holds the Lua state itself.
Methods
impl Lua
[src]
fn new() -> Lua
Creates a new Lua state.
Also loads the standard library.
fn load(&self, source: &str, name: Option<&str>) -> LuaResult<LuaFunction>
Loads a chunk of Lua code and returns it as a function.
The source can be named by setting the name
parameter. This is
generally recommended as it results in better error traces.
Equivalent to Lua's load
function.
fn exec<'lua, R: FromLuaMulti<'lua>>(
&'lua self,
source: &str,
name: Option<&str>
) -> LuaResult<R>
&'lua self,
source: &str,
name: Option<&str>
) -> LuaResult<R>
Execute a chunk of Lua code.
This is equivalent to simply loading the source with load
and then
calling the resulting function with no arguments.
Returns the values returned by the chunk.
fn eval<'lua, R: FromLuaMulti<'lua>>(&'lua self, source: &str) -> LuaResult<R>
Evaluate the given expression or chunk inside this Lua state.
If source
is an expression, returns the value it evaluates
to. Otherwise, returns the values returned by the chunk (if any).
fn create_string(&self, s: &str) -> LuaResult<LuaString>
Pass a &str
slice to Lua, creating and returning a interned Lua string.
fn create_table(&self) -> LuaResult<LuaTable>
Creates and returns a new table.
fn create_table_from<'lua, K, V, I>(&'lua self, cont: I) -> LuaResult<LuaTable> where
K: ToLua<'lua>,
V: ToLua<'lua>,
I: IntoIterator<Item = (K, V)>,
K: ToLua<'lua>,
V: ToLua<'lua>,
I: IntoIterator<Item = (K, V)>,
Creates a table and fills it with values from an iterator.
fn create_sequence_from<'lua, T, I>(&'lua self, cont: I) -> LuaResult<LuaTable> where
T: ToLua<'lua>,
I: IntoIterator<Item = T>,
T: ToLua<'lua>,
I: IntoIterator<Item = T>,
Creates a table from an iterator of values, using 1..
as the keys.
fn create_function<F>(&self, func: F) -> LuaResult<LuaFunction> where
F: 'static + for<'a> FnMut(&'a Lua, LuaMultiValue<'a>) -> LuaResult<LuaMultiValue<'a>>,
F: 'static + for<'a> FnMut(&'a Lua, LuaMultiValue<'a>) -> LuaResult<LuaMultiValue<'a>>,
Wraps a Rust function or closure, creating a callable Lua function handle to it.
fn create_thread<'lua>(
&'lua self,
func: LuaFunction<'lua>
) -> LuaResult<LuaThread<'lua>>
&'lua self,
func: LuaFunction<'lua>
) -> LuaResult<LuaThread<'lua>>
Wraps a Lua function into a new thread (or coroutine).
Equivalent to coroutine.create
.
fn create_userdata<T>(&self, data: T) -> LuaResult<LuaUserData> where
T: LuaUserDataType,
T: LuaUserDataType,
Create a Lua userdata object from a custom userdata type.
fn globals(&self) -> LuaResult<LuaTable>
Returns a handle to the global environment.
fn coerce_string<'lua>(
&'lua self,
v: LuaValue<'lua>
) -> LuaResult<LuaString<'lua>>
&'lua self,
v: LuaValue<'lua>
) -> LuaResult<LuaString<'lua>>
Coerces a Lua value to a string.
The value must be a string (in which case this is a no-op) or a number.
fn coerce_integer(&self, v: LuaValue) -> LuaResult<LuaInteger>
Coerces a Lua value to an integer.
The value must be an integer, or a floating point number or a string that can be converted to an integer. Refer to the Lua manual for details.
fn coerce_number(&self, v: LuaValue) -> LuaResult<LuaNumber>
Coerce a Lua value to a number.
The value must be a number or a string that can be converted to a number. Refer to the Lua manual for details.
fn from<'lua, T: ToLua<'lua>>(&'lua self, t: T) -> LuaResult<LuaValue<'lua>>
fn to<'lua, T: FromLua<'lua>>(&'lua self, value: LuaValue<'lua>) -> LuaResult<T>
fn pack<'lua, T: ToLuaMulti<'lua>>(
&'lua self,
t: T
) -> LuaResult<LuaMultiValue<'lua>>
&'lua self,
t: T
) -> LuaResult<LuaMultiValue<'lua>>
Packs up a value that implements ToLuaMulti
into a LuaMultiValue
instance.
This can be used to return arbitrary Lua values from a Rust function back to Lua.
fn unpack<'lua, T: FromLuaMulti<'lua>>(
&'lua self,
value: LuaMultiValue<'lua>
) -> LuaResult<T>
&'lua self,
value: LuaMultiValue<'lua>
) -> LuaResult<T>
Unpacks a LuaMultiValue
instance into a value that implements FromLuaMulti
.
This can be used to convert the arguments of a Rust function called by Lua.