Struct tlua::LuaCodeFromReader[][src]

pub struct LuaCodeFromReader<R>(pub R);
Expand description

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 = tlua::Lua::new();

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

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

Tuple Fields

0: R

Trait Implementations

Formats the value using the given formatter. Read more

Push the value into lua by value

Same as push_into_lua but can only succeed and is only available if Err implements Into<Void>. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.