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 withLuaCodeFromReader
.
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