macro_rules! reg {
($(($name:expr, $func:expr)),* $(,)?) => { ... };
($($func:ident),* $(,)?) => { ... };
}Expand description
Generates a list of named functions (&[Reg]) to be used in module creation.
The macro takes as input a list of the functions to put in the Reg slice. The list’s elements can be:
- A tuple comprising of the function’s name (as a
CStr) and the function itself (as aCFunction):
lua.return_module(reg![
(c"foo", foo), // Any expression can be used inside the tuple!
(c"bar", if condition { bar } else { baz })
])- Just the function itself (as a
CFunction), the function’s name will be derived from the given identifier:
// Only identifiers (no expressions) can be used here.
lua.register_module(c"my_global_module", reg![foo, bar, baz]);(All elements of the input list must be specified the same way.)
The generated slice can be passed to various functions used in module creation:
LuaState::return_modulereturns to the caller a table containing the slice’s functions.LuaState::register_modulesets as a new global a table containing the slice’s functions.LuaState::new_modulepushes onto the stack a table containing the slice’s functions.- (Etc.)