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

Re: [Xotcl] why Attribute is not imported?

From: Gustaf Neumann <neumann_at_wu.ac.at>
Date: Mon, 02 Nov 2009 09:52:07 +0100

Dear Mykhaylo,

The "slots" method changes the namespace to
make it convenient for the user to write
"Attribute name" and not
"Attribute test1::Test::slot::name".

The following snipped shows a simple solution,
but this is not nice either. With Tcl 8.5,
one could use instead of the "namespace import ..."
"namespace path ::xotcl" before "Attribute...".

namespace eval ::test1 {
    namespace import ::xotcl::*
    Class Test -slots {
      namespace import ::xotcl::*
      Attribute name
    }
    namespace export Test
}

This solution works, but is not nice either.
If you include the "contains" method below
in your script, your original example will
work as expected. I am planning to use this
definition in the 1.6.5 release.

best regards
-gustaf neumann


==============================
::xotcl::Object instproc contains {
  {-withnew:boolean true}
  -object
  {-class ::xotcl::Object}
  cmds} {
    if {![info exists object]} {set object [::xotcl::self]}
    if {![::xotcl::my isobject $object]} {
      $class create $object
      $object requireNamespace
      namespace eval $object {namespace import ::xotcl::*}
    }
    if {$withnew} {
      set m [::xotcl::ScopedNew new \
                 -inobject $object -withclass $class -volatile]
      ::xotcl::Class instmixin add $m end
      namespace eval $object $cmds
      ::xotcl::Class instmixin delete $m
    } else {
      namespace eval $object $cmds
    }
  }
==============================

Mykhaylo Sorochan schrieb:
> Hello,
>
> Why in the following code launched from tclsh I get the error:
> invalid command name "Attribute" during '::test1::Test slots'
>
> ######
> package provide test1 0.1
> package require XOTcl
>
> namespace eval ::test1 {
> namespace import ::xotcl::*
> Class Test -slots {
> Attribute name
> }
> namespace export Test
> }
> namespace import ::test1::*
> ######
>
> XOTcl 1.6.4, works ok from xotclsh and when 'namespace import ::xotcl::*'
> comes right after 'package require XOTcl' and not within test1 namespace.
>
> Thanks.
>
>