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

Class reflection for embedding #1158

Open
ConorDamery opened this issue Mar 21, 2023 · 3 comments
Open

Class reflection for embedding #1158

ConorDamery opened this issue Mar 21, 2023 · 3 comments

Comments

@ConorDamery
Copy link

ConorDamery commented Mar 21, 2023

Currently there doesn't seem to be a way to inspect a class and its methods/properties from C/Cpp.
Lua uses a table structure that can be inspected, and while it may be possible to add a properties map in the class with a specific name that can be used to manage the handles, this is at best an iffy workaround.

Any plans or suggestions on how this could/should be handled?

My first guess (which I'm not sure is the case already), would be to follow the same pattern Lua does by making the class handle also a map, so as long as you know the class name you can inspect its properties. This could also allow for checking if a handle has a callable method before using wrenCall and avoiding a runtime error.

@mhermier
Copy link
Contributor

There is a pull request/draft for a reflection API at #1006. I should update it sooner or later. I'm currently busy with other stuff, but I updated the change set last week to improve it.

@mhermier
Copy link
Contributor

Forgot to say, a quick and dirty way to do it would be to make Class iterable (by implementing iterate(_) and iteratorValue) so it output the symbols, but that will be not accepted in main for various reasons. But if you need it, you can easily implement it for yourself.

@dollerama
Copy link

Just wanted to add that attributes were added at some point. I suppose it might be a little time consuming but if you tag the methods/props you want to reflect though then you can access them elsewhere or in wren. I'm using attributes to serialize/deserialize.

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

No branches or pull requests

3 participants