[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Safely holding on to a <procedure> reference in C
From: |
Felix |
Subject: |
Re: [Chicken-users] Safely holding on to a <procedure> reference in C |
Date: |
Wed, 23 Feb 2011 02:53:20 -0500 (EST) |
From: Naitik Shah <address@hidden>
Subject: Re: [Chicken-users] Safely holding on to a <procedure> reference in C
Date: Tue, 22 Feb 2011 20:37:36 -0800
> Thanks for the replies. I haven't tried this yet, but I ended up going with
> another approach which seems to work. It's basically a callback index. The
> code is pretty buggy and all (like what happens after the number of
> callbacks hits the long limit), please ignore since I'm mostly just
> experimenting so far, but the basic idea is:
>
> (define _callbacks (make-hash-table))
> (define _callbackIndex 0)
> (define (get-callback index)
> (hash-table-ref _callbacks index))
> (define (register-callback! cb)
> (set! _callbackIndex (+ _callbackIndex 1))
> (hash-table-set! _callbacks _callbackIndex cb)
> _callbackIndex)
> (define (delete-callback! index)
> (hash-table-delete! _callbacks index))
>
>
> And I pass a integer callback index instead of the scheme object. Full
> source here: https://gist.github.com/2b3884461320db313188
>
> Would be interested to hear thoughts about this approach.
Perfectly reasonable and probably much simpler to handle on the
C side.
cheers,
felix
Re: [Chicken-users] Safely holding on to a <procedure> reference in C, Felix, 2011/02/22