Next Previous Contents

41. SLclass_register_class

Synopsis

Register a new data type with the interpreter

Usage

int SLclass_register_class (cl, type, sizeof_type, class_type)

    SLang_Class_Type *cl
    unsigned char type
    unsigned int sizeof_type
    unsigned char class_type
Description

The SLclass_register_class function is used to register a new class or data type with the interpreter. If successful, the function returns 0, or upon failure, it returns -1.

The first parameter, cl, must have been previously obtained via the SLclass_allocate_class function.

The second parameter, type specifies the data type of the new class. It must be an unsigned character with value greater that 127. The values in the range 0-127 are reserved for internal use by the library.

The size that the data type represents in bytes is specified by the third parameter, sizeof_type. This value should not be confused with the sizeof the structure that represents the data type, unless the data type is of class SLANG_CLASS_TYPE_VECTOR or SLANG_CLASS_TYPE_SCALAR. For pointer objects, the value of this parameter is just sizeof(void *).

The final parameter specifies the class type of the data type. It must be one of the values:

     SLANG_CLASS_TYPE_SCALAR
     SLANG_CLASS_TYPE_VECTOR
     SLANG_CLASS_TYPE_PTR
     SLANG_CLASS_TYPE_MMT
The SLANG_CLASS_TYPE_SCALAR indicates that the new data type is a scalar. Examples of scalars in SLANG_INT_TYPE and SLANG_DOUBLE_TYPE.

Setting class_type to SLANG_CLASS_TYPE_VECTOR implies that the new data type is a vector, or a 1-d array of scalar types. An example of a data type of this class is the SLANG_COMPLEX_TYPE, which represents complex numbers.

SLANG_CLASS_TYPE_PTR specifies the data type is of a pointer type. Examples of data types of this class include SLANG_STRING_TYPE and SLANG_ARRAY_TYPE. Such types must provide for their own memory management.

Data types of class SLANG_CLASS_TYPE_MMT are pointer types except that the memory management, i.e., creation and destruction of the type, is handled by the interpreter. Such a type is called a memory managed type. An example of this data type is the SLANG_FILEPTR_TYPE.

Notes

See the S-Lang Library C Programmer's Guide for more information.

See Also

SLclass_allocate_class


Next Previous Contents