On 03/29/14 20:01, CJS wrote:
> I've been using a medium-sized C library. Most of the library calls look 
> something like
> 
> XXXXaction(context, arg1, arg2)
> 
> Where XXXX is the name of the library, action is the action to take, and 
> context is an opaque pointer defined by the library to keep all the state 
> related to these actions.
> 
> Is there a simple way to wrap this library so I could make calls that look 
> like
> 
> context.action(arg1, arg2)?
> 
> I'm hoping for something with less manual work than having to wrap each 
> individual function call. Especially since the types involved in the library 
> can be somewhat complex and require trawling through multiple header files to 
> find out the true definition.
> 

The problem description is a little vague, at least w/o more context. If
you control D's view of that opaque structure then the simpliest solution
would be something like:

   struct XXXXContext {
      auto ref opDispatch(string NAME, Args...)(Args args) {
         return mixin("XXXX"~NAME~"(&this, args)");
      }
   }

artur

Reply via email to