Struct tlua::LuaCode

source ·
pub struct LuaCode<'a>(pub &'a str);
Expand description

Wrapper around a &str. 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 parsing error, you must use the checked_set method instead of set.

Note: This struct is a wrapper around LuaCodeFromReader. There’s no advantage in using it except that it is more convenient. More advanced usages (such as returning a Lua function from a Rust function) can be done with LuaCodeFromReader.

Example

let lua = tlua::Lua::new();
lua.checked_set("hello", &tlua::LuaCode("return 5")).unwrap();

let r: i32 = lua.eval("return hello();").unwrap();
assert_eq!(r, 5);

Tuple Fields§

§0: &'a str

Trait Implementations§

Formats the value using the given formatter. Read more
Error that can happen when pushing a value.
Pushes the value on the top of the stack. 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.