Return type and arguments template?

Kirk McDonald kirklin.mcdonald at gmail.com
Tue Sep 26 22:19:04 PDT 2006


Don Clugston wrote:
> Johan Granberg wrote:
> 
>> Can a function pointer or delegates arguments and return type bee 
>> determined by a template. I'm trying to create bindings to another 
>> language and would love to be able to export a function just by writing
>> registerFunction(&functionName);
> 
> 
> Yes, it's possible. Depending on what you want to do, you can do it the 
> C++ way, with a series of templates; or for just linking you can use the 
> .mangleof property. Look up 'PyD' for bindings to Python with a syntax 
> like that.
> 

To be strictly accurate, Pyd takes the functions to be bound as alias 
template parameters. You wrap a D function with:

def!(functionName, "functionName");

The "def" template function has a number of template arguments but no 
function arguments. The above calls def with D's property syntax.

Pyd does not (yet) use .mangleof in any capacity. The function name must 
be specified explicitly as a string literal template argument.

As for deriving the various bits of a function pointer or delegate type, 
I suggest looking at the FuncMeta module in Tom S's Bind package. It 
currently lives here:

http://www.mat.uni.torun.pl/~h3r3tic/bind.rar

I am currently in the midst of thrashing Pyd until it uses that package.

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org



More information about the Digitalmars-d-learn mailing list