[Xotcl] Initialisation arguments

Gustaf Neumann neumann at wu-wien.ac.at
Sat Oct 21 10:33:19 CEST 2006


Kristoffer Lawson schrieb:
>
> I don't mean the state of the object at time of calling, in the sense 
> of slots, but the values passed to the constructor on object creation. 
> The args to 'init'. The reason for this is that it might not be enough 
> to just create the object with the appropriate state, but it might 
> need to go through the 'init' stage as well, so the proper 
> initialisation chain is done (f.ex. might be calls to other things 
> taking place there, registration with managers etc). After that, slots 
> can be set.
i see, you mean the per-object parameterization; the arguments to the 
object/class creation are not stored explicitely
in XOTcl. However, the simplest way to save these is to provide a 
per-class mixin for overloading the standard
configure behavior. The following should do it:

  Object instmixin add [Class new -instproc configure args {my set 
__configure_values $args; next}]

Now we create a class and a few objects

  Class C -parameter {{x 0}}
  C create c1
  C create c2 -x 10
  C create c3 a -x 100

... and print the stored configure values:

  puts [list [c1 x] [c1 set __configure_values] \
          [c2 x] [c2 set __configure_values] \
          [c3 x] [c3 set __configure_values] ]

  # outputs: 0 {} 10 {-x 10} 100 {a -x 100}

Naturally, this works for classes as well:

  puts [C set __configure_values]

  # outputs: -parameter {{x 0}}

Does this help?

-gustaf neumann




More information about the Xotcl mailing list