Running a delegate inside a C function

2014-06-07 Thread Denis Martinez via Digitalmars-d-learn
I am trying to make a binding for the Jack Audio Connection Kit, which I figured would be a good exercise to start and hopefully to replace C++ for my long term audio work. I am making good progress (complete C API covered), and currently I am hitting a brick wall where delegates are concerned,

Re: Running a delegate inside a C function

2014-06-07 Thread Chris Cain via Digitalmars-d-learn
On Saturday, 7 June 2014 at 20:04:41 UTC, Denis Martinez via Digitalmars-d-learn wrote:     int ret = jack_set_process_callback(handle_, f, dg); dg here is giving you a pointer to the dg variable sitting on the stack. The stack is almost certainly getting overwritten at some point.

Re: Running a delegate inside a C function

2014-06-07 Thread Denis Martinez via Digitalmars-d-learn
On Saturday, 7 June 2014 at 20:37:48 UTC, Chris Cain wrote: On Saturday, 7 June 2014 at 20:21:26 UTC, Chris Cain wrote: On Saturday, 7 June 2014 at 20:04:41 UTC, Denis Martinez via Digitalmars-d-learn wrote:     int ret = jack_set_process_callback(handle_, f, dg); dg here is giving you a

Re: Running a delegate inside a C function

2014-06-07 Thread anonymous via Digitalmars-d-learn
On Saturday, 7 June 2014 at 21:18:39 UTC, Denis Martinez wrote: Thanks for the answer Chris, you are correct. I was expecting the closure to work similarly to Clang's blocks, which apparently it does not. I guess that delegates pass by copy, like structs do. So far I have tried a variety of

Re: Running a delegate inside a C function

2014-06-07 Thread Adam D. Ruppe via Digitalmars-d-learn
See my answer to this: http://stackoverflow.com/questions/22845175/pass-delegates-to-external-c-functions-in-d Since a delegate is two pointers and most C functions expect only one pointer, you need to do some kind of magic. There's one solution. Another is if the C function can pass a void*