Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros for easier userdata #14

Open
tomaka opened this issue Jul 30, 2014 · 4 comments
Open

Macros for easier userdata #14

tomaka opened this issue Jul 30, 2014 · 4 comments

Comments

@tomaka
Copy link
Owner

tomaka commented Jul 30, 2014

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.

@tomaka tomaka changed the title Create macros for easier userdata Macros for easier userdata Jul 30, 2014
@pczarn
Copy link
Contributor

pczarn commented Aug 7, 2014

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
        }
    }
}

@tomaka
Copy link
Owner Author

tomaka commented Aug 8, 2014

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.

@mkpankov
Copy link
Contributor

This stuff would be nightly-only, as it would be a compiler plugin, right?

@tomaka
Copy link
Owner Author

tomaka commented Apr 19, 2017

@mkpankov Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants