-
Notifications
You must be signed in to change notification settings - Fork 117
Access metatables of UserValue and Table #175
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
Comments
Hi, As far as other types, this is just how Lua is (with the exception of strings, where the metatable points to the |
Thank you for your reply! I understand that and don't wish to break rust's safety assumptions. I just noticed there is no reliable way in Lua to detect whether an object is callable, except by trying and catching exceptions. So, I wish to implement an is_callable function, in rust. But I cannot get the metatable for all Lua types from rust, hence this question whether something could be done about it or if I'm missing something. :-) |
Oops, my apologies! I see that I misread (or didn't quite read properly) your question. I agree that there isn't a way to do so at the moment (other than the clunky option of loading the debug library and calling |
Actually the metatables for userdata are full of landmines and rlua assumes they're in very particular states to maintain safety, it would be better probably to do something other than give the plain metatable back or it should at least be unsafe. |
Aha, I did wonder. Would something like a Or would it be safe enough to have a more general |
Hmm, for "my" problem the first one would probably suffice. |
Possible fix for mlua-rs#175.
rlua is going to be deprecated soon and this feature is already supported by mlua |
Background: I wanted to implement a library function in rust called "is_callable". It should check whether a Lua value is (a) a function or (b) some Lua object with a metatable that contains a callable __call entry.
I was able to get the metatables of tables from rust/rlua, but not for other types of Lua values...
The text was updated successfully, but these errors were encountered: