Nelarius / wrenpp

Minimal, zero dependency C++ binding generator for the Wren programming language
MIT License
98 stars 17 forks source link

[Question] How to use wrenpp to bind foreign hierarchies? #16

Open heretique opened 6 years ago

heretique commented 6 years ago

Hi, i'm using wrenpp an a toy game engine and I came to a use case where I'm a bit stuck. Suppose I have a base Node class and a Spatial class that inherits Node. Since in wren it is not possible to subclass a foreign class, in wrenpp I have to bind all the specific base class methods for each derived class each time. What would be the best approach to automate this in wrenpp?

Nelarius commented 6 years ago

It sure would be nice if subclasses could inherit foreign classes in Wren 🤔

Wren++ doesn't really help you in that regard, unfortunately! I would probably just dump the base class bindings in a function, which would be parametrized based on module and class name. At least the purpose of the code would be clear:

bind_node_impl(vm, "spatial_node", "SpatialNode");
bind_node_impl(vm, "ui_node", "UiNode");
// etc...

This isn't optimum, since you can't freely extend the hierarchy in Wren without modifying C++ 😞

Nelarius commented 6 years ago

I would actually be curious about how the guy behind the Luxe engine has worked around this problem, since the engine also uses Wren heavily.