Generating a method using a UDA

Melvin mxtcapps at gmail.com
Wed May 9 10:16:22 UTC 2018


I'm trying to find a friendly syntax for defining things in a 
framework. For context, I've been looking into finding a solution 
for this problem 
(https://github.com/GodotNativeTools/godot-d/issues/1) on the 
Godot-D project. I've done some investigating already, and it 
looks like I can only achieve what I want with a mixin, but I'd 
like to get a second opinion.

Say we have a class that defines a custom Signal (an event). In 
an ideal world, the syntax would work similarly to this:

class SomeNode : GodotScript!Node
{
     @Signal void testSignal(float a, long b);
     // The declaration above would trigger the generation of this 
line
     void testSignal(float a, long b) { 
owner.emitSignal("testSignal", a, b); }

     @Method emitTest()
     {
         testSignal(3.1415, 42);
     }
}


The reason I want to use a UDA is to stay consistent with the 
other UDAs already defined for Properties and Methods. It also 
looks friendlier than using a mixin. Does anyone here have any 
thoughts as to how this could work?

My main issue is injecting that generated method without 
resorting to using a mixin. I was hoping that any code I needed 
could be generated in the template that SomeNode inherits, but 
that doesn't look possible because I can't inspect the subclass 
(for good reason).


More information about the Digitalmars-d-learn mailing list