Struct hlua_badtouch::LuaFunction [] [src]

pub struct LuaFunction<L> { /* fields omitted */ }

Handle to a function in the Lua context.

Just like you can read variables as integers and strings, you can also read Lua functions by requesting a LuaFunction object. Once you have a LuaFunction you can call it with call().

Note: Passing parameters when calling the function is not yet implemented.

Example

let mut lua = hlua::Lua::new();
lua.execute::<()>("function foo() return 12 end").unwrap();

let mut foo: hlua::LuaFunction<_> = lua.get("foo").unwrap();
let result: i32 = foo.call().unwrap();
assert_eq!(result, 12);

Methods

impl<'lua, L> LuaFunction<L> where
    L: AsMutLua<'lua>, 
[src]

[src]

Calls the function. Doesn't allow passing parameters.

TODO: will eventually disappear and get replaced with call_with_args

Returns an error if there is an error while executing the Lua code (eg. a function call returns an error), or if the requested return type doesn't match the actual return type.

Note: In order to pass parameters, see call_with_args instead.

[src]

Calls the function with parameters.

TODO: should be eventually be renamed to call

You can either pass a single value by passing a single value, or multiple parameters by passing a tuple. If you pass a tuple, the first element of the tuple will be the first argument, the second element of the tuple the second argument, and so on.

Returns an error if there is an error while executing the Lua code (eg. a function call returns an error), if the requested return type doesn't match the actual return type, or if we failed to push an argument.

Example

let mut lua = hlua::Lua::new();
lua.execute::<()>("function sub(a, b) return a - b end").unwrap();

let mut foo: hlua::LuaFunction<_> = lua.get("sub").unwrap();
let result: i32 = foo.call_with_args((18, 4)).unwrap();
assert_eq!(result, 14);

[src]

Builds a new LuaFunction from the code of a reader.

Returns an error if reading from the Read object fails or if there is a syntax error in the code.

Example

use std::io::Cursor;

let mut lua = hlua::Lua::new();

let mut f = hlua::LuaFunction::load_from_reader(&mut lua, Cursor::new("return 8")).unwrap();
let ret: i32 = f.call().unwrap();
assert_eq!(ret, 8);

[src]

Builds a new LuaFunction from a raw string.

Note: This is just a wrapper around load_from_reader. There is no advantage in using load except that it is more convenient.

Trait Implementations

impl<L: Debug> Debug for LuaFunction<L>
[src]

[src]

Formats the value using the given formatter. Read more

impl<'lua, L> AsLua<'lua> for LuaFunction<L> where
    L: AsLua<'lua>, 
[src]

[src]

impl<'lua, L> AsMutLua<'lua> for LuaFunction<L> where
    L: AsMutLua<'lua>, 
[src]

[src]

Returns the raw Lua context.

impl<'lua, L> LuaRead<L> for LuaFunction<L> where
    L: AsMutLua<'lua>, 
[src]

[src]

Reads the data from Lua at a given position.

[src]

Reads the data from Lua.

Auto Trait Implementations

impl<L> Send for LuaFunction<L> where
    L: Send

impl<L> Sync for LuaFunction<L> where
    L: Sync