I’m trying to make extendable vtable, that will grow it’s “fields” (actually it’s AutoHashMap with enum key generated at comptime).
And HashMap should store function pointers.
I’ve tried *anyopaque, but eventually got this:
error: type '*const anyopaque' not a function
Is there way do define an opaque function pointer?
The solution I didn’t like (but I think there’s no choice) is to make defined function pointer, but with *anyopaque field. It means, that extra dereferencing would be needed.
Within your GenericElement defintion you have a getHandle function:
You could change that function so that it takes the event parameter as a comptime parameter and then write some comptime code to extract the right function pointer type based on the event tag and add that pointer cast within this function.
That way your usage code would actually work, without changing it, because your event parameters are already comptime known literals.
P.S I’m thinking how to do it properly in my project, since I don’t know at this step, if all the handles would have rigid types or they will be mutated depending on objects