Generating a method using a UDA

Simen Kjærås simen.kjaras at
Wed May 9 11:52:48 UTC 2018

On Wednesday, 9 May 2018 at 10:16:22 UTC, Melvin wrote:
> 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).

I'm afraid a mixin is the only real solution. You could also mark 
testSignal as abstract, and have a template generate an 
implementation class, but that would pollute every place where 
you want to use a SomeNode, with something like SomeNode n = 


More information about the Digitalmars-d-learn mailing list