Re: Building STk on HP-UX
> Does this approach make sense?
>
>
> (button "Frob" :command
> (create-callback table (lambda () (frob ...))))
>
> Create-callback interns the closure and associates it with a string. It
> returns a string that when executed by Tk looks up the calback by name and
> funcalls it. If you had one table per application, you could throw it away
> when the application is deactivated.
I did something related to this for bindings in STklos objects.
Here's an example from my code:
(define-binding bb '<3> (|X| |Y|)
(menu-post ih (- |X| 6) (- |Y| 6)))
What this does, roughly, is:
* Create a closure of two arguments, |X| and |Y|, with the obvious
definition. (bb and ih are of course defined in the scope.)
* Store the closure in a hash table associated with bb.
* Bind <3> in bb to "(XXXX %X %Y)", where XXXX is the address of the
closure.
The hash table ensures that if you later bind <3> to something else,
the old closure will get GCd.
There are a number of things I don't like about this--for example, it
doesn't work for various non-bind entities like menus, and it creates
a hash table for every Tk-object (actually every Tk-object that uses
define-binding). However, if I ignore the implementation and its
limitations, I really like using it.
If anyone's interested, I can mail out the code. It's a pretty
horrendous macro and an associated function, along with an extra slot
in Tk-object; it's not great, but it could be hacked into shape.
Received on Tue Feb 14 1995 - 22:30:16 CET
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST