Skip to content

Instantly share code, notes, and snippets.

@fkaa
Created June 19, 2017 11:48
Show Gist options
  • Save fkaa/07cb4093e9a0445c0c0cb224fa4f83a3 to your computer and use it in GitHub Desktop.
Save fkaa/07cb4093e9a0445c0c0cb224fa4f83a3 to your computer and use it in GitHub Desktop.
fn example() -> Result<()> {
let mut state = flu::State::new();
// lua_createtable and luaL_ref
let meta = flu::Table::reference(&state, |cxt| {
fn __add(stack: flu::FunctionStack) -> Result<i32> {
let a = stack.with_arg::<flu::Table, _, _>(1, |cxt| {
cxt.get::<f64>("a")
})?;
let b = stack.with_arg::<flu::Table, _, _>(2, |cxt| {
cxt.get::<f64>("a")
})?;
stack.push(a + b);
Ok(1)
}
cxt.set("__add", __add);
});
let b = 4;
state.set("test", flu::Table::new(|cxt| {
cxt.set("a", b);
cxt.set_meta(&meta);
}));
state.eval(r#"
test = test + test
print(test) -- prints 8
"#)?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment