chicken-users
[Top][All Lists]
Advanced

[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: Naitik Shah
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.


Thanks,
-Naitik

reply via email to

[Prev in Thread] Current Thread [Next in Thread]