Macros question

Hello, I am working on Shrine implementation for Crystal (https://github.com/jetrockets/shrine.cr).

Currently my biggest problem is a plugin system. I tried to implement it with macros and everything was good until I tried to inherit plugins list from a superclass.

Here is an example https://play.crystal-lang.org/#/r/7tfe.

As far as I understand {{@type.superclass.constant(:PLUGINS)}} should return Array of plugins for C class, but it is blank…

1 Like

/cc @Blacksmoke16

You do:

PLUGINS << plugin

and that happens at runtime.

You need to do:

{% PLUGINS << plugin %}

(without the resolve bit)

and then it will work.

I also recommend removing everything unnecessary to demostrante a problem or question. There’s InstanceMethods and many other things that are not relevant to the question, and at least in me it caused an effect of “this is too much code, I’ll skip helping” (well, then I did it anyway, but with less code there’s more change to get help).

5 Likes

Finally, I get it to work!

https://play.crystal-lang.org/#/r/7tqz

Features:

  • Inheritance of plugins from base class
  • Protection from loading same plugin several times