4 ms·
Why not export a struct with function pointers like everyone else? You should take a look at how VST plugins are implemented. You load the dlo, call a functio
by jawngee 14y ago
Why not export a struct with function pointers like everyone else? You should take a look at how VST plugins are implemented.
You load the dlo, call a function passing in your own struct of application functions and get back a struct of plugin functions. No weird naming conventions needed, easily version-able. Tried and true.
- sausagefeet 14y agoI was kind of surprised too since Eli is seems pretty smart. Perhaps I'm missing something?
- delinka 14y agoI don't know whether this was the author's intent, but it's better to start simpler (not in designs but in concepts - arguably, structs are simpler than funky naming conventions) for the beginner and less experienced dev. The struct method is a powerful one, yet not one grokked simply by the neophyte. There probably needs to be a Part II.
- tptacek 14y agoOn the contrary, setting up a regime of specially-named functions is error-prone and clunky, and structures with function pointers are a language idiom in C, and, finally, if you're too new to the language to understand function pointers, you can't use either technique, because both rely on function pointers. Ultimately, the real problem is that teaching bad designs to people because they're new to the language is counterproductive.
- iopuy 14y agoCould you provide an example of this so us neophytes could learn from it?
- eliben 14y agoWhat weird naming conventions? There's only one symbol in each plugin the application knows about, the init_<pluginname> function, but at least one symbol is usually necessary. Do you mean the plugins calling PluginManager functions to register hooks? I just wanted to present a simple method without a lot of code. Using structs is an alternative, more convenient in some cases. One problem with it is that it imposes an ABI, while one registration function per hook does not. Anyhow, this was just a basic example showing how plugins can work. I do plan to explore alternatives in the future, and specifically looking at existing pluggable applications (Apache, for instance)