Thanks for the explanation Erik!  Sorry I misspelled your name. :)

On Sun, Apr 2, 2017 at 12:11 PM, Erik Gustafson <erik.d.gustaf...@gmail.com>
wrote:

> Michel,
>
> Here's a link to exactly what you need:
>
> https://github.com/michelp/0pl/blob/master/zmq/zctx.l#L5
>
>
> I totally forgot about 0pl - That's it! Thanks for the quick response.
>
>
> a thread in the archives where Alexander explains it to me...
>
>
> I wasn't able to find it, but here's my attempt:
>
> Passing a pointer reference to 'native' is similar to the integer
> reference example found here: https://software-labde/
> doc/native.html#structArg
> <https://software-lab.de/doc/native.html#structArg>.
>
> It becomes clearer when we think of a reference (a pointer) to a pointer
> instead as a buffer of 8 bytes - sizeof(*ptr) | sizeof(long) - that
> contains a pointer.
>
> We can pass this buffer to 'native' with:
>
>    (list NIL (8) (cons Ptr 8))
>
> 'native' then receives something like:
>
>    (NIL (8) (35680432 . 8))
>
> In English, I'd read this as "a buffer of 8 bytes - that we won't need to
> reference again (hence NIL) - initialized to contain our pointer, literally
> 'long 35680432' in C."
>
> That's a mouthful. Let's create a naive little helper function so we don't
> have to think about it anymore:
>
>    (de &ptr (P) (list NIL (8) (cons P 8)))
>
> A bit more intuitive now:
>
>    : (setq *N (native "libzyre.so" "zyre_create" 'N "node"))
>    -> 36274819
>    : (setq *N (native "libzyre.so" "zyre_destroy" NIL (&ptr *N)))
>    -> NIL
>
> Look how nicely '&ptr' pairs with the global variable naming convention ;)
> not that I'd ever recommend a global variable for each node on a network...
>
> Corrections/clarifications encouraged!
>
> Cheers,
> Erik
>
>

Reply via email to