# squserdata.h

    00001 /*  see copyright notice in squirrel.h */
    00002 #ifndef _SQUSERDATA_H_
    00003 #define _SQUSERDATA_H_
    00004
    00005 struct SQUserData : SQDelegable
    00006 {
    00007   SQUserData(SQSharedState *ss){ _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
    00008   ~SQUserData()
    00009   {
    00010     REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
    00011     SetDelegate(NULL);
    00012   }
    00013   static SQUserData* Create(SQSharedState *ss, SQInteger size)
    00014   {
    00015     SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1));
    00016     new (ud) SQUserData(ss);
    00017     ud->_size = size;
    00018     ud->_typetag = 0;
    00019     return ud;
    00020   }
    00021 #ifndef NO_GARBAGE_COLLECTOR
    00022   void Mark(SQCollectable **chain);
    00023   void Finalize(){SetDelegate(NULL);}
    00024 #endif
    00025   void Release() {
    00026     if (_hook) _hook(_val,_size);
    00027     SQInteger tsize = _size - 1;
    00028     this->~SQUserData();
    00029     SQ_FREE(this, sizeof(SQUserData) + tsize);
    00030   }
    00031
    00032   SQInteger _size;
    00033   SQRELEASEHOOK _hook;
    00034   SQUserPointer _typetag;
    00035   SQChar _val[1];
    00036 };
    00037
    00038 #endif //_SQUSERDATA_H_