Moonwards-Virtual-Moon
Moonwards-Virtual-Moon copied to clipboard
See if we can implement basic reflection features for GDScript.
Gdscript offers no reflection features at all. We often need to know the class name we're dealing with as well as it's inheritance chain, see if we can expose that from within C++.
- [ ] Research
Reading a bit on the topic, seems some of the Object functions could be used to get something similar to reflection Edit: Though it would be heavily String based
Reading a bit on the topic, seems some of the Object functions could be used to get something similar to reflection Edit: Though it would be heavily String based
Yeah I've been reading about this as well, I've been meaning to implement some base classes we'd use for moonwards in GDNative instead, to give us fine-tuned APIs. MwNode
& MwSpatial
are examples that would be moved to GDNative at some point, this is also to allow for a better networking implementation.
As mentioned above, Godot does have some ways that will tell you which objects you're dealing with.
The Object class itself has methods like get_class(), is_class(class_name) or get_script().
Also there is a global object ClassDB which will give you metadata access for every available class. Function here will be like class_has_method(class, method) or get_class_list()
The override of a get_class like here may be helpful for us, since by default it is returning the base class we've inherited, and not the one declared with class_name keyword. There is an open issue regarding that, although hard to say if it's going to be implemented in Godot 4.0.
One can set it's own metadata with Object: set_meta(name, value) and get_meta(name).
Are those methods insufficient for our needs?
As far as I could tell, ClassDB
isn't exposed to GDScript
And they are sufficient as preliminary functionality, but the room for error is huge when implemented that way - hence why it's better implemented through GDNative
Also combined with the networking layer we'll write, it makes sense to move this to GDNative
The case that is relevant right now is for perfect reflections. I wrote it up as a separate issue, actually - #338
This is a different thing here, i think you meant to go there.
To confirm, this issue is in relation to GDScript reflection, as in the programming language paradigm, not the reflection of surfaces in the game