Library writing - delegates or fp's?
BCS
BCS at pathlink.com
Wed Jun 21 09:16:17 PDT 2006
Chad J wrote:
> So I have decided to roll my own GUI library, one dedicated to computer
> games. But I've run into a bit of an unpleasant design problem - for
> handling callbacks, how should my library expose function pointers and
> delegates?
>
[...]
a while back someone found out that you can take a delegate and replace
the internal function pointer with a regular function pointer and it
still works just fine. Given this, you could wright a little
function*-to-delegate function and let people do this
UseThisCallback(int delegate(int));
int delegate(int) f2d(int function(int) fnp){...}
int fn(int);
void main()
{
UseThisCallback(f2d(&fn));
}
I known this is an *ugly* hack, OTOH maybe Walter can be convinced to
add a function-pointer to delegate cast that does this in a consistent
manner.
cast(int delegate(int))&fn
More information about the Digitalmars-d-learn
mailing list