Live data from Hacker News

Plugins in C

eli.thegreenplace.net

1–10 of 12 posts

Re: Plugins in C

#3
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.

Re: Plugins in C

#6
post #3

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.

I was kind of surprised too since Eli is seems pretty smart. Perhaps I'm missing something?

Re: Plugins in C

#7
post #3

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.

I 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.

Re: Plugins in C

#9
post #7
post #3

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.

I 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.

On 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.

Re: Plugins in C

#10
post #4

On a related note: Be wary of the dlclose() function, it may not necessarily free any resources[1] and not every libc implements it correctly[2]. 1. http://www.openwall.com/lists/musl/2012/08/20/1 2. http://www.openwall.com/lists/musl/2012/08/23/20

If you really need to demand-load and demand-unload lots and lots and lots of plugins --- and that's the only design I can think of where dlclose matters, but maybe there are others --- fork a plugin host process from the main process, and kill it off when you're done with the plugins. You can use anonymous shared memory to communicate between the two processes (since there's a simple parent/child relationship).
Post reply on HN