I am working on a nim wrapper for the CLAP audio plugin format. I can compile an audio plugin written in nim as a dynlib and load it into a test host ( written in c ). The host is finding the exposed methods and endpoints that it needs to create a plugin instance, however I am having trouble passing a pointer to a nim object to the host.
The c code that is calling into the nim dynlib looks like this ( simplified ) auto inst = factory->create(); Run create() should return an instance of a plugin, however it returns NULL. the nim code looks like this ( simplified ) proc create(): ptr ClapPlugin = var plugin: ClapPlugin = ClapPlugin( desc: addr(sMyPlugDesc), startProcessing: myPlugStartProcessing, stopProcessing: myPlugStopProcessing, process: myPlugProcess, ) echo "created plugin" return addr plugin Run The echo message indicates that the message is being called correctly, however the variable "inst" in the c part is NULL. In c the plugin creation method would look like this: clap_plugin_t *my_plug_create(const clap_host_t *host) { my_plug_t *p = calloc(1, sizeof(*p)); p->plugin.desc = &s_my_plug_desc; p->plugin.start_processing = my_plug_start_processing; p->plugin.stop_processing = my_plug_stop_processing; p->plugin.process = my_plug_process; return &p->plugin; } Run I am guessing that the instantiated object is being deleted as it leaves the proc's scope. Do I need to alloc it's memory explicitly in nim? or can I use a ref object? Any tips would be appreciated.