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

Re: [Xotcl] proper way to access xotcl classes

From: Matthew Smith <chedderslam_at_gmail.com>
Date: Wed, 7 May 2008 13:09:35 -0500

Thank you for the help.

Now I am getting another error I don't understand.

invalid command name "my".

It seems like it is not getting to use XOTcl commands. Here is what I have:
----------------------------------------------------------
package require XOTcl
::xotcl::Class Stack
Stack instproc init {} {
    # Constructor
    my instvar things
    set things ""
}
Stack instproc push {thing} {
    my instvar things
    set things [concat [list $thing] $things]
    return $thing
}
Stack instproc pop {} {
    my instvar things
    set top [lindex $things 0]
    set things [lrange $things 1 end]
    return $top
}

set s1 [Stack new]
----------------------------------------------------------

On Wed, May 7, 2008 at 1:01 PM, Kristoffer Lawson <setok_at_scred.com> wrote:

>
> On 7 May 2008, at 20:54, Matthew Smith wrote:
>
>
> > ---------------------------------------------------------
> > How do I access the class methods(i guess they are called) from within
> > the tcl file?
> > The examples show this:
> > --------------------------------------------------------
> > # Create Object s1 of class Stack
> > % Stack s1
> > ::s1
> > % s1 push a
> > a
> > % s1 push b
> > b
> > % s1 push c
> > c
> > % s1 pop
> > c
> > % s1 pop
> > b
> > # Delete object s1
> > s1 destroy
> > --------------------------------------------------------
> > I have tried this:
> > set s1 [Stack]
> >
> >
> Either this:
>
> set s1 [Stack new]
>
> or
>
> set s1 [Stack s1]
>
> The first version gives you an automatically named object, which is
> probably what you usually want to do. You can also explicitly name objects
> with the latter version (something you cannot do with Java and stuff).
> Mostly you wont need to do this, but there are situations when it's useful.
>
> / http://www.scred.com/
> / http://www.fishpool.com/~setok/<http://www.fishpool.com/%7Esetok/>
>
>
>