www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: Bind object to member function

reply Li Jie <cpunion gmail.com> writes:

sort of dispatch mechanism, delegates do not directly allow this. Thanks. Delegate is very cool, but it bind too early.
Aug 13 2006
parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Li Jie wrote:
 If you're looking for pointers to member functions to implement some
 sort of dispatch mechanism, delegates do not directly allow this.

Thanks. Delegate is very cool, but it bind too early.

My own Pyd library requires this functionality to implement its class wrapping. I do not endorse this practice, but the dirty hack it uses to get the functionality is found here: http://dsource.org/projects/pyd/browser/trunk/infrastructure/pyd/dg_convert.d In essense, it constructs a delegate from an Object instance and a regular function pointer. It takes advantage of how delegates are represented internally, but this behavior is not guaranteed by the spec. It is therefore firmly in the realm of "dirty hacks." Note that this module requires the ftype module originally written by Daniel Keep. The version of ftype in Pyd is slightly modified from his original. -- Kirk McDonald Pyd: Wrapping Python with D http://dsource.org/projects/pyd/wiki
Aug 14 2006