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
[src]
Creates a new Lua state and loads standard library without the debug
library.
unsafe fn new_with_debug() -> Lua
[src]
Creates a new Lua state and loads the standard library including the debug
library.
The debug library is very unsound, loading it and using it breaks all the guarantees of rlua.
fn load(&self, source: &str, name: Option<&str>) -> Result<Function>
[src]
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>
) -> Result<R>
[src]
&'lua self,
source: &str,
name: Option<&str>
) -> Result<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,
name: Option<&str>
) -> Result<R>
[src]
&'lua self,
source: &str,
name: Option<&str>
) -> Result<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) -> Result<String>
[src]
Pass a &str
slice to Lua, creating and returning an interned Lua string.
fn create_table(&self) -> Result<Table>
[src]
Creates and returns a new table.
fn create_table_from<'lua, K, V, I>(&'lua self, cont: I) -> Result<Table<'lua>> where
K: ToLua<'lua>,
V: ToLua<'lua>,
I: IntoIterator<Item = (K, V)>,
[src]
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) -> Result<Table<'lua>> where
T: ToLua<'lua>,
I: IntoIterator<Item = T>,
[src]
T: ToLua<'lua>,
I: IntoIterator<Item = T>,
Creates a table from an iterator of values, using 1..
as the keys.
fn create_function<'lua, A, R, F>(&'lua self, func: F) -> Result<Function<'lua>> where
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + FnMut(&'lua Lua, A) -> Result<R>,
[src]
A: FromLuaMulti<'lua>,
R: ToLuaMulti<'lua>,
F: 'static + FnMut(&'lua Lua, A) -> Result<R>,
Wraps a Rust function or closure, creating a callable Lua function handle to it.
Examples
Create a function which prints its argument:
let lua = Lua::new(); let greet = lua.create_function(|_, name: String| { println!("Hello, {}!", name); Ok(()) });
Use tuples to accept multiple arguments:
let lua = Lua::new(); let print_person = lua.create_function(|_, (name, age): (String, u8)| { println!("{} is {} years old!", name, age); Ok(()) });
fn create_thread<'lua>(&'lua self, func: Function<'lua>) -> Result<Thread<'lua>>
[src]
Wraps a Lua function into a new thread (or coroutine).
Equivalent to coroutine.create
.
fn create_userdata<T>(&self, data: T) -> Result<AnyUserData> where
T: UserData,
[src]
T: UserData,
Create a Lua userdata object from a custom userdata type.
fn globals(&self) -> Table
[src]
Returns a handle to the global environment.
fn coerce_string<'lua>(&'lua self, v: Value<'lua>) -> Result<String<'lua>>
[src]
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: Value) -> Result<Integer>
[src]
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: Value) -> Result<Number>
[src]
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 pack<'lua, T: ToLua<'lua>>(&'lua self, t: T) -> Result<Value<'lua>>
[src]
Converts a value that implements ToLua
into a Value
instance.
fn unpack<'lua, T: FromLua<'lua>>(&'lua self, value: Value<'lua>) -> Result<T>
[src]
Converts a Value
instance into a value that implements FromLua
.
fn pack_multi<'lua, T: ToLuaMulti<'lua>>(
&'lua self,
t: T
) -> Result<MultiValue<'lua>>
[src]
&'lua self,
t: T
) -> Result<MultiValue<'lua>>
Converts a value that implements ToLuaMulti
into a MultiValue
instance.
fn unpack_multi<'lua, T: FromLuaMulti<'lua>>(
&'lua self,
value: MultiValue<'lua>
) -> Result<T>
[src]
&'lua self,
value: MultiValue<'lua>
) -> Result<T>
Converts a MultiValue
instance into a value that implements FromLuaMulti
.