#[lua_methods]Expand description
Attribute macro on impl blocks โ exposes public methods to Lua.
For each pub fn with a &self or &mut self receiver, generates:
- A static
fn(l: &mut LuaState) -> LuaResult<usize>wrapper - Automatic parameter extraction from Lua stack
- Automatic return value conversion to Lua
Methods are accessible from Lua via obj:method(args) syntax.
ยงExample
โ
#[lua_methods]
impl Point {
pub fn distance(&self) -> f64 {
(self.x * self.x + self.y * self.y).sqrt()
}
pub fn translate(&mut self, dx: f64, dy: f64) {
self.x += dx;
self.y += dy;
}
}