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