www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Return type and arguments template?

reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
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);
Similarly can the components of a struct or class bee extracted. (in 
short i'm trying to build a sort of syntax tree describing the 
fuctions/delegates)
Sep 24 2006
parent reply Don Clugston <dac nospam.com.au> writes:
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.
 Similarly can the components of a struct or class bee extracted. (in 
 short i'm trying to build a sort of syntax tree describing the 
 fuctions/delegates)
No, you can't find the members of a class or struct at compile time. Not yet, anyway. At run time you can use DDL (at dsource). BTW -- You keep making a spelling mistake, it's time someone corrected you. "bee" is an insect that buzzes and makes honey. The word you want is "be". <g>
Sep 25 2006
parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
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
Sep 26 2006
parent reply Johan Granberg <lijat.meREM OVEgmail.com> writes:
Kirk McDonald wrote:
 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.
Thanks for pointing me to the bind package (I did know about the pyd alias thing) as for the mangleof property is their complete documentation somewhere the d abi page had some TBDs in it.
Sep 27 2006
parent Don Clugston <dac nospam.com.au> writes:
Johan Granberg wrote:
 Kirk McDonald wrote:
 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.
Thanks for pointing me to the bind package (I did know about the pyd alias thing) as for the mangleof property is their complete documentation somewhere the d abi page had some TBDs in it.
There's no documentation, but see my meta.demangle and meta.nameof modules in DDL on dsource; I believe it covers 100% of the cases (std.demangle misses quite a few). If you find something it can't demangle, let me know! But seriously, you probably don't need anything other than meta.nameof.
Sep 27 2006