hlua
hlua copied to clipboard
Macros for easier userdata
Something like would be great:
#[lua-userdata]
struct Foo {
value: int,
}
#[lua-userdata]
impl Foo {
pub fn get_value(&self) -> int {
self.value
}
}
lua.set("foo", Foo{ value: 5 }); // automatically fills the metatable
lua.execute("return foo:get_value()"); // would return 5
There are probably technical limitations, limiting this syntax extension to a single impl block, but maybe there's a trick that I didn't think about.
The trick is processing an entire module at once. I might make an attempt at implementation.
#[lua-userdata]
mod bar {
struct Foo {
value: int,
}
impl Foo {
pub fn get_value(&self) -> int {
self.value
}
}
}
That would be very nice!
However the rest of the library is not ready to support this just yet. The parameters of a callback are currently loaded by copy only, and you don't want to make a copy of your object when you call a method.
This stuff would be nightly-only, as it would be a compiler plugin, right?
@mkpankov Yes