Next: , Previous: , Up: C   [Index]


OBJECT typedef

OBJECT typedef

At the lowest level, ctalk declares objects as pointers to an OBJECT struct. You can access an object’s members if you assign an object’s value to a C variable of the type OBJECT *, as in this example.

Object new myObject;
OBJECT *myObjectValue;

myObjectValue = myObject value;

if (!strcmp (myObjectValue -> CLASSNAME, "Object"))
   printf ("myObjectValues class is, \"Object.\"\n");

The declaration of the OBJECT type is contained in include/object.h.

typedef struct _object OBJECT;
. . .
struct _object {
  char sig[16];
  char __o_name[MAXLABEL];
  char __o_classname[MAXLABEL];
  OBJECT *__o_class;
  char __o_superclassname[MAXLABEL];
  OBJECT *__o_superclass;
  OBJECT *__o_p_obj;
  VARTAG *__o_vartags;
  char *__o_value;
  METHOD *instance_methods,
    *class_methods;
  int scope;
  int nrefs;
  int attrs
  struct _object *classvars;
  struct _object *instancevars;    
  struct _object *next;
  struct _object *prev;
};

Note that __o_name, __o_classname, __o_superclassname, and __o_value are all char *, even if the object belongs to a class like Integer or Float. The struct members __o_class and __o_superclass contain pointers to the library class and superclass entries, which are also objects.

For numeric classes, the value member contains a formatted representation of a numeric value. Examples of directly assigning values to objects are given in the section about writing methods. See Method API.

Ctalk uses the members instance_methods, class_methods, classvars for class objects.

The sig member contains a numeric stamp that verifies that the OBJECT * refers to a valid object.

The scope member describes an object’s scope. The scope can be one of GLOBAL_VAR, LOCAL_VAR, ARG_VAR, RECEIVER_VAR, PROTOTYPE_VAR, or BLOCK_VAR.

The nrefs member keeps track of the number of references that exist to an object at run time. Every time ctalk creates a reference to an object, internally ctalk increments nrefs. When ctalk deletes a reference, it decrements nrefs. When nrefs drops to zero, ctalk deletes the object.

The attrs member is a combination of one or more object attributes. The next section describes object attributes in more detail.

The tag member is an abbreviation for the __o_vartags -> tag -> var_decl -> name member; that is, the object’s primary label.


Next: , Previous: , Up: C   [Index]