MT_CLONED=12,
MT_NEWSLOT=13,
MT_DELSLOT=14,
- MT_LAST = 15,
+ MT_TOSTRING=15,
+ MT_NEWMEMBER=16,
+ MT_INHERITED=17,
+ MT_LAST = 18
};
#define MM_ADD _SC("_add")
#define MM_CLONED _SC("_cloned")
#define MM_NEWSLOT _SC("_newslot")
#define MM_DELSLOT _SC("_delslot")
+#define MM_TOSTRING _SC("_tostring")
+#define MM_NEWMEMBER _SC("_newmember")
+#define MM_INHERITED _SC("_inherited")
#define MINPOWER2 4
struct SQRefCounted
{
- unsigned int _uiRef;
+ SQRefCounted() { _uiRef = 0; _weakref = NULL; }
+ virtual ~SQRefCounted();
+ SQWeakRef *GetWeakRef(SQObjectType type);
+ SQUnsignedInteger _uiRef;
+ struct SQWeakRef *_weakref;
virtual void Release()=0;
};
+struct SQWeakRef : SQRefCounted
+{
+ void Release();
+ SQObject _obj;
+};
+
+#define _realval(o) (type((o)) != OT_WEAKREF?(SQObject)o:_weakref(o)->_obj)
+
struct SQObjectPtr;
#define __AddRef(type,unval) if(ISREFCOUNTED(type)) \
{ \
unval.pRefCounted->_uiRef++; \
- }
+ }
#define __Release(type,unval) if(ISREFCOUNTED(type) && ((--unval.pRefCounted->_uiRef)<=0)) \
{ \
#define _class(obj) ((obj)._unVal.pClass)
#define _instance(obj) ((obj)._unVal.pInstance)
#define _delegable(obj) ((SQDelegable *)(obj)._unVal.pDelegable)
+#define _weakref(obj) ((obj)._unVal.pWeakRef)
+#define _refcounted(obj) ((obj)._unVal.pRefCounted)
#define _rawval(obj) ((obj)._unVal.pRefCounted)
#define _stringval(obj) (obj)._unVal.pString->_val
assert(_unVal.pThread);
__AddRef(_type,_unVal);
}
+ SQObjectPtr(SQWeakRef *pWeakRef)
+ {
+ _type=OT_WEAKREF;
+ _unVal.pWeakRef=pWeakRef;
+ assert(_unVal.pWeakRef);
+ __AddRef(_type,_unVal);
+ }
SQObjectPtr(SQFunctionProto *pFunctionProto)
{
_type=OT_FUNCPROTO;
}
SQObjectPtr(SQInteger nInteger)
{
+ _unVal.pUserPointer=NULL;
_type=OT_INTEGER;
_unVal.nInteger=nInteger;
}
SQObjectPtr(SQFloat fFloat)
{
+ _unVal.pUserPointer=NULL;
_type=OT_FLOAT;
_unVal.fFloat=fFloat;
}
SQObjectPtr(bool bBool)
{
+ _unVal.pUserPointer=NULL;
_type = OT_BOOL;
_unVal.nInteger = bBool?1:0;
}
_unVal.pUserPointer=NULL;
}
inline SQObjectPtr& operator=(const SQObjectPtr& obj)
- {
+ {
SQObjectType tOldType;
SQObjectValue unOldVal;
tOldType=_type;
return *this;
}
inline SQObjectPtr& operator=(const SQObject& obj)
- {
+ {
SQObjectType tOldType;
SQObjectValue unOldVal;
tOldType=_type;
#endif
struct SQDelegable : public CHAINABLE_OBJ {
- virtual bool GetMetaMethod(SQMetaMethod mm,SQObjectPtr &res);
+ bool SetDelegate(SQTable *m);
+ virtual bool GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res);
SQTable *_delegate;
};
-unsigned int TranslateIndex(const SQObjectPtr &idx);
+SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx);
typedef sqvector<SQObjectPtr> SQObjectPtrVec;
-typedef sqvector<int> SQIntVec;
+typedef sqvector<SQInteger> SQIntVec;
+
#endif //_SQOBJECT_H_