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

Re: [Xotcl] Initialisation arguments

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Sat, 21 Oct 2006 10:33:19 +0200

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