luafuncs macro
This commit is contained in:
parent
860654d4ba
commit
99f100c812
1
main.lua
1
main.lua
@ -3,6 +3,7 @@ print("Hello from a lua script!")
|
||||
function init()
|
||||
print("Hello from \"init\"")
|
||||
couch.debug("init")
|
||||
couch.say_hello("dane", "Hi!")
|
||||
end
|
||||
|
||||
function update(delta)
|
||||
|
@ -19,6 +19,7 @@ impl Lua {
|
||||
// Create the ``couch'' api
|
||||
let couch = ctx.create_table().unwrap();
|
||||
couch.set("debug", ctx.create_function(debug).unwrap()).unwrap();
|
||||
couch.set("say_hello", ctx.create_function(say_hello).unwrap()).unwrap();
|
||||
// Hook in to globals
|
||||
ctx.globals().set("couch", couch).unwrap();
|
||||
let path = std::path::Path::new("main.lua");
|
||||
@ -43,8 +44,22 @@ impl ScriptLang for Lua {
|
||||
}
|
||||
}
|
||||
|
||||
fn debug(_: &LuaContext, msg: String) -> Result<(), mlua::Error> {
|
||||
println!("Couch Debug Message: {}", msg);
|
||||
Ok(())
|
||||
macro_rules! luafuncs {
|
||||
($($name:ident($($arg:ident: $type: ty),*) $body:block),*) => {
|
||||
$(
|
||||
fn $name(_: &LuaContext, ($($arg),*,): ($($type),*,)) -> Result<(), mlua::Error> $body
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
luafuncs!{
|
||||
debug(msg: String) {
|
||||
println!("Couch Debug Message: {}", msg);
|
||||
Ok(())
|
||||
},
|
||||
say_hello(name: String, msg: String) {
|
||||
println!("Couch says {} to {}", msg, name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user