View · Search · Index
No registered users in community xowiki
in last 10 minutes

XOTcl/NX mailing list by object move?

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Mon, 20 Mar 2006 11:57:07 +0100

Koen Danckaert schrieb:

> I use the following two global procs for that:
>
> proc myproc {args} {linsert $args 0 [uplevel 1 self]}
> proc myvar {var} {return [uplevel 1 self]::$var}

as kristoffer noted (and as in my earlier version shows)
it makes sense to add a requireNamespace to myvar.
a slightly faster version of myproc is:

> button $x -command [myproc show 1 2 3]
> ...
> trace add variable [myvar status] write [myproc statusevent]

you can use here as well

   my trace add variable status write [myproc statusevent]

>
> (Note: in fact the "uplevel" in the definition of myproc/myvar is not
> even necessary. It seems that [self] always refers to the last Xotcl
> object on the callstack.)


  self returns the current object from the xtcl call stack. if one calls
a pure tcl-proc or tcl-cmd
  from an xotcl method, the same xotcl callstack entry is still active.
so [self] continues
  to return "the right" obejct.

  therefore, a slightly faster version is:

  proc myproc {args} {linsert $args 0 [self]}


  seems as a good idea to add both methods to the xotcl distribution.

  Shouldn't we use "mymethod" instead of myproc, this function will not
only work for
  procs, but for instprocs and cmds as well....

-gustaf neumann