fixed warnings in squirrel
[supertux.git] / src / squirrel / squirrel / squserdata.h
1 /*      see copyright notice in squirrel.h */
2 #ifndef _SQUSERDATA_H_
3 #define _SQUSERDATA_H_
4
5 struct SQUserData : SQDelegable
6 {
7         SQUserData(SQSharedState *ss){ _uiRef = 0; _delegate = 0; _hook = NULL; INIT_CHAIN(); ADD_TO_CHAIN(&_ss(this)->_gc_chain, this); }
8         ~SQUserData()
9         {
10                 REMOVE_FROM_CHAIN(&_ss(this)->_gc_chain, this);
11                 SetDelegate(NULL);
12         }
13         static SQUserData* Create(SQSharedState *ss, int size)
14         {
15                 SQUserData* ud = (SQUserData*)SQ_MALLOC(sizeof(SQUserData)+(size-1));
16                 new (ud) SQUserData(ss);
17                 ud->_size = size;
18                 ud->_typetag = 0;
19                 return ud;
20         }
21 #ifndef NO_GARBAGE_COLLECTOR
22         void Mark(SQCollectable **chain);
23         void Finalize(){SetDelegate(NULL);}
24 #endif
25         void Release() {
26                 if (_hook) _hook(_val,_size);
27                 int tsize = _size - 1;
28                 this->~SQUserData();
29                 SQ_FREE(this, sizeof(SQUserData) + tsize);
30         }
31         void SetDelegate(SQTable *mt)
32         {
33                 if (mt) __ObjAddRef(mt);
34                 __ObjRelease(_delegate);
35                 _delegate = mt;
36         }
37
38         
39         int _size;
40         SQRELEASEHOOK _hook;
41         unsigned int _typetag;
42         SQChar _val[1];
43 };
44
45 #endif //_SQUSERDATA_H_