-/* see copyright notice in squirrel.h */\r
-#ifndef _SQCLASS_H_\r
-#define _SQCLASS_H_\r
-\r
-struct SQInstance;\r
-\r
-struct SQClassMemeber {\r
- SQClassMemeber(){}\r
- SQClassMemeber(const SQClassMemeber &o) {\r
- val = o.val;\r
- attrs = o.attrs;\r
- }\r
- SQObjectPtr val;\r
- SQObjectPtr attrs;\r
-};\r
-\r
-typedef sqvector<SQClassMemeber> SQClassMemeberVec;\r
-\r
-struct SQClass : public CHAINABLE_OBJ\r
-{\r
- SQClass(SQSharedState *ss,SQClass *base);\r
-public:\r
- static SQClass* Create(SQSharedState *ss,SQClass *base) {\r
- SQClass *newclass = (SQClass *)SQ_MALLOC(sizeof(SQClass));\r
- new (newclass) SQClass(ss, base);\r
- return newclass;\r
- }\r
- ~SQClass();\r
- bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);\r
- bool Get(const SQObjectPtr &key,SQObjectPtr &val) {\r
- if(_members->Get(key,val)) {\r
- val = (type(val) == OT_INTEGER?_defaultvalues[_integer(val)].val:_methods[(int)_userpointer(val)].val);\r
- return true;\r
- }\r
- return false;\r
- }\r
- bool SetAttributes(const SQObjectPtr &key,const SQObjectPtr &val);\r
- bool GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval);\r
- void Lock() { _locked = true; if(_base) _base->Lock(); }\r
- void Release() { sq_delete(this, SQClass); }\r
- void Finalize();\r
- void Mark(SQCollectable ** );\r
- int Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);\r
- SQInstance *CreateInstance();\r
- SQTable *_members;\r
- //SQTable *_properties;\r
- SQClass *_base;\r
- SQClassMemeberVec _defaultvalues;\r
- SQClassMemeberVec _methods;\r
- SQObjectPtrVec _metamethods;\r
- SQObjectPtr _attributes;\r
- unsigned int _typetag;\r
- bool _locked;\r
-};\r
-\r
-struct SQInstance : public SQDelegable \r
-{\r
- void Init(SQSharedState *ss);\r
- SQInstance(SQSharedState *ss, SQClass *c);\r
- SQInstance(SQSharedState *ss, SQInstance *c);\r
-public:\r
- static SQInstance* Create(SQSharedState *ss,SQClass *theclass) {\r
- SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));\r
- new (newinst) SQInstance(ss, theclass);\r
- return newinst;\r
- }\r
- SQInstance *Clone(SQSharedState *ss)\r
- {\r
- SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));\r
- new (newinst) SQInstance(ss, this);\r
- return newinst;\r
- }\r
- ~SQInstance();\r
- bool Get(const SQObjectPtr &key,SQObjectPtr &val) {\r
- if(_class->_members->Get(key,val)) {\r
- val = (type(val) == OT_INTEGER?_values[_integer(val)]:_class->_methods[(int)_userpointer(val)].val);\r
- return true;\r
- }\r
- return false;\r
- }\r
- bool Set(const SQObjectPtr &key,const SQObjectPtr &val) {\r
- SQObjectPtr idx;\r
- if(_class->_members->Get(key,idx) && type(idx) == OT_INTEGER) {\r
- _values[_integer(idx)] = val;\r
- return true;\r
- }\r
- return false;\r
- }\r
- void Release() { \r
- if (_hook) { _hook(_userpointer,0);}\r
- sq_delete(this, SQInstance);\r
- }\r
- void Finalize();\r
- void Mark(SQCollectable ** );\r
- bool InstanceOf(SQClass *trg);\r
- bool GetMetaMethod(SQMetaMethod mm,SQObjectPtr &res);\r
-\r
- SQClass *_class;\r
- SQUserPointer _userpointer;\r
- SQRELEASEHOOK _hook;\r
- SQObjectPtrVec _values;\r
-};\r
-\r
-#endif //_SQCLASS_H_\r
+/* see copyright notice in squirrel.h */
+#ifndef _SQCLASS_H_
+#define _SQCLASS_H_
+
+struct SQInstance;
+
+struct SQClassMember {
+ SQClassMember(){}
+ SQClassMember(const SQClassMember &o) {
+ val = o.val;
+ attrs = o.attrs;
+ }
+ SQObjectPtr val;
+ SQObjectPtr attrs;
+};
+
+typedef sqvector<SQClassMember> SQClassMemberVec;
+
+struct SQClass : public CHAINABLE_OBJ
+{
+ SQClass(SQSharedState *ss,SQClass *base);
+public:
+ static SQClass* Create(SQSharedState *ss,SQClass *base) {
+ SQClass *newclass = (SQClass *)SQ_MALLOC(sizeof(SQClass));
+ new (newclass) SQClass(ss, base);
+ return newclass;
+ }
+ ~SQClass();
+ bool NewSlot(const SQObjectPtr &key,const SQObjectPtr &val);
+ bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
+ if(_members->Get(key,val)) {
+ val = (type(val) == OT_INTEGER?_defaultvalues[_integer(val)].val:_methods[_integer(val)].val);
+ return true;
+ }
+ return false;
+ }
+ bool SetAttributes(const SQObjectPtr &key,const SQObjectPtr &val);
+ bool GetAttributes(const SQObjectPtr &key,SQObjectPtr &outval);
+ void Lock() { _locked = true; if(_base) _base->Lock(); }
+ void Release() { sq_delete(this, SQClass); }
+ void Finalize();
+ void Mark(SQCollectable ** );
+ int Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
+ SQInstance *CreateInstance();
+ SQTable *_members;
+ //SQTable *_properties;
+ SQClass *_base;
+ SQClassMemberVec _defaultvalues;
+ SQClassMemberVec _methods;
+ SQObjectPtrVec _metamethods;
+ SQObjectPtr _attributes;
+ unsigned int _typetag;
+ bool _locked;
+};
+
+struct SQInstance : public SQDelegable
+{
+ void Init(SQSharedState *ss);
+ SQInstance(SQSharedState *ss, SQClass *c);
+ SQInstance(SQSharedState *ss, SQInstance *c);
+public:
+ static SQInstance* Create(SQSharedState *ss,SQClass *theclass) {
+ SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));
+ new (newinst) SQInstance(ss, theclass);
+ return newinst;
+ }
+ SQInstance *Clone(SQSharedState *ss)
+ {
+ SQInstance *newinst = (SQInstance *)SQ_MALLOC(sizeof(SQInstance));
+ new (newinst) SQInstance(ss, this);
+ return newinst;
+ }
+ ~SQInstance();
+ bool Get(const SQObjectPtr &key,SQObjectPtr &val) {
+ if(_class->_members->Get(key,val)) {
+ val = (type(val) == OT_INTEGER?_values[_integer(val)]:_class->_methods[_integer(val)].val);
+ return true;
+ }
+ return false;
+ }
+ bool Set(const SQObjectPtr &key,const SQObjectPtr &val) {
+ SQObjectPtr idx;
+ if(_class->_members->Get(key,idx) && type(idx) == OT_INTEGER) {
+ _values[_integer(idx)] = val;
+ return true;
+ }
+ return false;
+ }
+ void Release() {
+ if (_hook) { _hook(_userpointer,0);}
+ sq_delete(this, SQInstance);
+ }
+ void Finalize();
+ void Mark(SQCollectable ** );
+ bool InstanceOf(SQClass *trg);
+ bool GetMetaMethod(SQMetaMethod mm,SQObjectPtr &res);
+
+ SQClass *_class;
+ SQUserPointer _userpointer;
+ SQRELEASEHOOK _hook;
+ SQObjectPtrVec _values;
+};
+
+#endif //_SQCLASS_H_