Wrapping C APIs in D functions of same name?

Tyler Knott tywebmail at mailcity.com
Sat Jan 27 22:15:13 PST 2007


Rick Mann wrote:
> I'm writing interface modules for some C APIs. In a few cases, I need to pre- and post-process some of the data passed to and from them. I'd like to wrap the methods in "pure" D methods with the same name as the C methods I want to call. Is there any way to do this?
> 
> TIA,
> Rick
Yes.  Because module imports can be declared as "private" (and are by 
default), you can simply write two seperate modules.  One would contain 
all the extern (C) declarations, and the other containing the D 
wrappers.  The module with the wrappers would import the module with the 
externs (privately), and call the extern functions using the fully 
qualified name of them (e.g. in a module foo.bar with a function func 
taking (param), you'd call it as foo.bar.func(param)).


More information about the Digitalmars-d-learn mailing list