Struct hlua_badtouch::LuaCodeFromReader [] [src]

pub struct LuaCodeFromReader<R>(pub R);

Wrapper around a Read object. When pushed, the content will be parsed as Lua code and turned into a function.

Since pushing this value can fail in case of a reading error or a parsing error, you must use the checked_set method instead of set.

Example: returning a Lua function from a Rust function

use std::io::Cursor;

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

lua.set("call_rust", hlua::function0(|| -> hlua::LuaCodeFromReader<Cursor<String>> {
    let lua_code = "return 18;";
    return hlua::LuaCodeFromReader(Cursor::new(lua_code.to_owned()));
}));

let r: i32 = lua.execute("local lua_func = call_rust(); return lua_func();").unwrap();
assert_eq!(r, 18);

Trait Implementations

impl<R: Debug> Debug for LuaCodeFromReader<R>
[src]

[src]

Formats the value using the given formatter. Read more

impl<'lua, L, R> Push<L> for LuaCodeFromReader<R> where
    L: AsMutLua<'lua>,
    R: Read
[src]

Error that can happen when pushing a value.

[src]

Pushes the value on the top of the stack. Read more

[src]

Same as push_to_lua but can only succeed and is only available if Err is Void.

impl<'lua, L, R> PushOne<L> for LuaCodeFromReader<R> where
    L: AsMutLua<'lua>,
    R: Read
[src]

Auto Trait Implementations

impl<R> Send for LuaCodeFromReader<R> where
    R: Send

impl<R> Sync for LuaCodeFromReader<R> where
    R: Sync