Moonwards-Virtual-Moon icon indicating copy to clipboard operation
Moonwards-Virtual-Moon copied to clipboard

See if we can implement basic reflection features for GDScript.

Open Reousa opened this issue 4 years ago • 6 comments

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

Reousa avatar Apr 25 '20 12:04 Reousa

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

yaelatletl avatar Apr 27 '20 23:04 yaelatletl

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.

Reousa avatar Apr 28 '20 00:04 Reousa

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?

SiudaPL avatar Jun 02 '20 10:06 SiudaPL

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

Reousa avatar Jun 02 '20 17:06 Reousa

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.

Moonwards avatar Jun 23 '20 17:06 Moonwards

To confirm, this issue is in relation to GDScript reflection, as in the programming language paradigm, not the reflection of surfaces in the game

Reousa avatar Jun 23 '20 17:06 Reousa