1 /* see copyright notice in squirrel.h */
\r
7 struct SQClassMemeber {
\r
9 SQClassMemeber(const SQClassMemeber &o) {
\r
17 typedef sqvector<SQClassMemeber> SQClassMemeberVec;
\r
19 struct SQClass : public CHAINABLE_OBJ
\r
21 SQClass(SQSharedState *ss,SQClass *base);
\r
23 static SQClass* Create(SQSharedState *ss,SQClass *base) {
\r
24 SQClass *newclass = (SQClass *)SQ_MALLOC(sizeof(SQClass));
\r
25 new (newclass) SQClass(ss, base);
\r
29 bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);
\r
30 bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
\r
31 if(_members->Get(key,val)) {
\r
32 val = (type(val) == OT_INTEGER?_defaultvalues[_integer(val)].val:_methods[(int)_userpointer(val)].val);
\r
37 bool SetAttributes(const SQObjectPtr &key,const SQObjectPtr &val);
\r
38 bool GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval);
\r
39 void Lock() { _locked = true; if(_base) _base->Lock(); }
\r
40 void Release() { sq_delete(this, SQClass); }
\r
42 void Mark(SQCollectable ** );
\r
43 int Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
\r
44 SQInstance *CreateInstance();
\r
46 //SQTable *_properties;
\r
48 SQClassMemeberVec _defaultvalues;
\r
49 SQClassMemeberVec _methods;
\r
50 SQObjectPtrVec _metamethods;
\r
51 SQObjectPtr _attributes;
\r
52 unsigned int _typetag;
\r
56 struct SQInstance : public SQDelegable
\r
58 void Init(SQSharedState *ss);
\r
59 SQInstance(SQSharedState *ss, SQClass *c);
\r
60 SQInstance(SQSharedState *ss, SQInstance *c);
\r
62 static SQInstance* Create(SQSharedState *ss,SQClass *theclass) {
\r
63 SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));
\r
64 new (newinst) SQInstance(ss, theclass);
\r
67 SQInstance *Clone(SQSharedState *ss)
\r
69 SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));
\r
70 new (newinst) SQInstance(ss, this);
\r
74 bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
\r
75 if(_class->_members->Get(key,val)) {
\r
76 val = (type(val) == OT_INTEGER?_values[_integer(val)]:_class->_methods[(int)_userpointer(val)].val);
\r
81 bool Set(const SQObjectPtr &key,const SQObjectPtr &val) {
\r
83 if(_class->_members->Get(key,idx) && type(idx) == OT_INTEGER) {
\r
84 _values[_integer(idx)] = val;
\r
90 if (_hook) { _hook(_userpointer,0);}
\r
91 sq_delete(this, SQInstance);
\r
94 void Mark(SQCollectable ** );
\r
95 bool InstanceOf(SQClass *trg);
\r
96 bool GetMetaMethod(SQMetaMethod mm,SQObjectPtr &res);
\r
99 SQUserPointer _userpointer;
\r
100 SQRELEASEHOOK _hook;
\r
101 SQObjectPtrVec _values;
\r
104 #endif //_SQCLASS_H_
\r