Distinguishing a pointer to a function and a closure
Adam D. Ruppe
destructionator at gmail.com
Mon Nov 11 13:31:26 UTC 2019
On Monday, 11 November 2019 at 13:10:44 UTC, berni44 wrote:
> (a normal delegate seems to be an Object somehow, though).
The .ptr method is a pointer to the data associated with the
delegate. It might be an object (class or struct) or it might be
a memory block (for local variables on the stack or a closure).
There is no way to tell the difference between these in D, even
at runtime. The .ptr member drops all source information.
The code should probably be rewritten to avoid inspecting the
.ptr member entirely. Maybe have it wrap the function internally
- right at the point when it receives the delegate or write a
whole new function that takes object and method separately - or
something.
More information about the Digitalmars-d-learn
mailing list