-
I'm looking at https://github.com/khvzak/mlua/blob/master/examples/userdata.rs and I see this in Rectangle::add_methods():
but in the usage of that it's doing this:
which seems wrong on the surface since I think it's creating 2 rectangles (one in Rust and then another in lua)? Alternatively, looking at https://github.com/khvzak/mlua/blob/master/examples/guided_tour.rs I see this instead of defining a MetaMethod::Call constructor:
and that makes sense but now I don't know what the right way to do this is between the two. If I just do this:
I get this error: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's true but you need an instance of Userdata to exec In your example |
Beta Was this translation helpful? Give feedback.
It's true but you need an instance of Userdata to exec
__call
OR just a new function to construct it (as it's done invec2_constructor
).In your example
Animal
is just a Rust type that implementsUserData
but in Lua it must be an entity in a global namespace to use it on that way.It your case it should be a "dummy" instance of
Animal
or you can make it as a function and remove__call
constructor.In another words - an existing instance of Animal that constructs new instances of self.