Skip to content

Slightly confused about UserData constructors #170

Answered by khvzak
Luminoth asked this question in Q&A
Discussion options

You must be logged in to vote

which seems wrong on the surface since I think it's creating 2 rectangles (one in Rust and then another in lua)?

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 in vec2_constructor ).

In your example Animal is just a Rust type that implements UserData 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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Luminoth
Comment options

Answer selected by Luminoth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants