How do I pass a delegate to an external C function taking a function pointer, in D?
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
Let me cross post what I said on the newsgroup:
You can't do it directly in general, unless you can modify the C function, then you can hack around it, but a delegate and a regular function pointer are pretty different animals.
But perhaps you can magic hack it. Observe:
What bindDelegate does is create a special static variable and function for that specific call. It is as if we wrote a separate function and global to hold it.
The
__FILE__
,__LINE__
things are a filthy hack to make it instantiate a separate variable+function pair for different lines so the global variable holding the delegate won't be so easily overwritten.