Created
June 19, 2017 11:48
-
-
Save fkaa/07cb4093e9a0445c0c0cb224fa4f83a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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