Macro make_lua_fn

Source
macro_rules! make_lua_fn {
    ($lua_inst:ident, $to_call: ident, $(
        ($argname: ident, $argtype: ty))
        ,
        *
        ) => { ... };
    ($lua_inst:ident, $to_call: ident) => { ... };
}
Expand description

Allows to easily bind rust functions to your Lua code

THIS USES UNWRAPS INTERNALLY, SO IT MIGHT PANIC

§Arguments

  • lua_inst - Your lua instance, create with rlua::Lua::new()
  • to_call - The rust function you want to call, the lua function will have the same name
  • argname - Optional parameter for functions with parameters: Specifies the name of the arg
  • argtype - Optional parameter for functions with parameters: Specifies the type of the arg

§Example

Rust setup:

let lua_inst = rlua::Lua::new();
make_lua_fn!(lua_inst, print_hello);
make_lua_fn!(lua_inst, print_arg, (arg, u32));
make_lua_fn!(lua_inst, print_multi_args, (arg, u32), (arg2, f32));
make_lua_fn!(lua_inst, print_multi_args_names, (argNameCanBeAnything, u32), (arg2, f32));

Lua usage:

print_hello()
print_arg(12)
print_multi_args(12, 4.0)