Re: [incr Tcl] state of this project?

From: Gustaf Neumann (neumann_at_wu-wien.ac.at)
Date: 10/24/03


Date: 24 Oct 2003 11:46:30 -0700

David Gravereaux <davygrvy@pobox.com> wrote in message news:<iu5ipvcafktilnpfvnfll2gajf8fkd4kfp@4ax.com>...
> First I guess we need to make a blank class, then fill it with methods,
> yes?

yes; look at the following snipplet; it creates
a class named "MyClass" and adds an instance method named
"foo" to it. Here i used the definition of set (the method
is normally not exported). For real code, one should
check the return-codes and do ref-counting for the
Tcl_Obj.

    XOTcl_Class *class, *myclass;
    Tcl_Obj *name = Tcl_NewStringObj("MyClass", -1);
    /* get the class structure from metaclass "Class" */
    class = XOTclGetClass(in, "::xotcl::Class");
    /* create MyClass */
    XOTclCreateClass(in, name, class);
    /* get the class structure from myclass */
    myclass = XOTclGetClass(in, "MyClass");
    /* add the instance method */
    XOTclAddIMethod(in, myclass, "foo",
       (Tcl_ObjCmdProc*)XOTclOSetMethod, 0, 0);

 from the tcl shell, you can use after loading

   MyClass create o1
   o1 foo a 100

 This sets an instance variable a of Object o1 to 100.

-gustaf
PS: certainly, you can create the class via
   Tcl_Eval(in, "::xotcl::Class create MyClass")
 to save most of the code.



Relevant Pages

  • Re: How to do that
    ... You should try to copy & paste your real code, ... class FooA: public Foo ... virtual int Init(); ... virtual int Close; ...
    (comp.lang.cpp)
  • Re: How to return reference to class object from functions?
    ... > Suppose I have a function foo() and a class definition myClass, ... How can I return the reference from foo? ...
    (comp.lang.cpp)
  • Re: Implementing interface problem
    ... > returns an object of MyClass type. ... > public class MyClasss: ICloneable ... > of the class that implement this interface. ... public Foo Clone() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: new X vs new X()
    ... > class the call new MyClass is the same with the call new MyClass ... > (assuming the class has a default constructor). ... object of type Foo that has the same value that an otherwise uninitialized ... > pointer to an int that is not innitialized (it is not guaranteed to be ...
    (comp.lang.cpp)
  • Re: How to return reference to class object from functions?
    ... > Suppose I have a function foo() and a class definition myClass, ... Static myObject may fail in ...
    (comp.lang.cpp)