Next Previous Contents

42. SLclass_set_destroy_function

Synopsis

Set the destroy method callback for a data type

Usage

int SLclass_set_destroy_function (cl, destroy_fun)

    SLang_Class_Type *cl
    void (*destroy_fun) (unsigned char, VOID_STAR);
Description

SLclass_set_destroy_function is used to set the destroy callback for a data type. The data type's class cl must have been previously obtained via a call to SLclass_allocate_class. When called, destroy_fun will be passed two arguments: a unsigned char which represents the data type, and the address of the object to be destroyed.

SLclass_set_destroy_function returns zero upon success, and -1 upon failure.

Example

The destroy method for SLANG_STRING_TYPE looks like:

    static void string_destroy (unsigned char type, VOID_STAR ptr)
    {
       char *s = *(char **) ptr;
       if (s != NULL) SLang_free_slstring (*(char **) s);
    }
Notes

Data types of class SLANG_CLASS_TYPE_SCALAR do not require a destroy callback. However, other classes do.

See Also

SLclass_allocate_class, SLclass_register_class


Next Previous Contents