3 SquirrelObject::SquirrelObject(
void)
8 SquirrelObject::~SquirrelObject()
14 SquirrelObject::SquirrelObject(
const SquirrelObject &o)
20 SquirrelObject::SquirrelObject(HSQOBJECT o)
26 void SquirrelObject::Reset(
void) {
32 SquirrelObject SquirrelObject::Clone()
35 if(GetType() == OT_TABLE || GetType() == OT_ARRAY)
39 ret.AttachToStackObject(-1);
46 SquirrelObject & SquirrelObject::operator =(
const SquirrelObject &o)
56 SquirrelObject & SquirrelObject::operator =(SQInteger n)
59 AttachToStackObject(-1);
64 void SquirrelObject::ArrayAppend(
const SquirrelObject &o)
74 void SquirrelObject::AttachToStackObject(SQInteger idx)
83 BOOL_T SquirrelObject::SetDelegate(SquirrelObject &obj)
85 if(obj.GetType() == OT_TABLE ||
86 obj.GetType() == OT_NULL) {
102 SquirrelObject SquirrelObject::GetDelegate()
105 if(_o._type == OT_TABLE || _o._type == OT_USERDATA)
107 SQInteger top =
sq_gettop(SquirrelVM::_VM);
110 ret.AttachToStackObject(-1);
119 return sq_isnull(_o);
122 BOOL_T SquirrelObject::IsNumeric()
const 124 return sq_isnumeric(_o);
127 SQInteger SquirrelObject::Len()
const 130 if(sq_isarray(_o) || sq_istable(_o) || sq_isstring(_o)) {
133 sq_pop(SquirrelVM::_VM,1);
138 #define _SETVALUE_INT_BEGIN \ 139 BOOL_T ret = FALSE; \ 140 SQInteger top = sq_gettop(SquirrelVM::_VM); \ 141 sq_pushobject(SquirrelVM::_VM,_o); \ 142 sq_pushinteger(SquirrelVM::_VM,key); 144 #define _SETVALUE_INT_END \ 145 if(SQ_SUCCEEDED(sq_rawset(SquirrelVM::_VM,-3))) { \ 148 sq_settop(SquirrelVM::_VM,top); \ 189 SQInteger top =
sq_gettop(SquirrelVM::_VM);
193 if(SQ_SUCCEEDED(
sq_rawset(SquirrelVM::_VM,-3))) {
200 #define _SETVALUE_STR_BEGIN \ 201 BOOL_T ret = FALSE; \ 202 SQInteger top = sq_gettop(SquirrelVM::_VM); \ 203 sq_pushobject(SquirrelVM::_VM,_o); \ 204 sq_pushstring(SquirrelVM::_VM,key,-1); 206 #define _SETVALUE_STR_END \ 207 if(SQ_SUCCEEDED(sq_rawset(SquirrelVM::_VM,-3))) { \ 210 sq_settop(SquirrelVM::_VM,top); \ 250 BOOL_T SquirrelObject::SetUserPointer(
const SQChar * key,SQUserPointer up) {
256 SQUserPointer SquirrelObject::GetUserPointer(
const SQChar * key) {
257 SQUserPointer ret =
NULL;
260 sq_pop(SquirrelVM::_VM,1);
262 sq_pop(SquirrelVM::_VM,1);
266 BOOL_T SquirrelObject::SetUserPointer(INT_T key,SQUserPointer up) {
272 SQUserPointer SquirrelObject::GetUserPointer(INT_T key) {
273 SQUserPointer ret =
NULL;
276 sq_pop(SquirrelVM::_VM,1);
278 sq_pop(SquirrelVM::_VM,1);
284 BOOL_T SquirrelObject::NewUserData(
const SQChar * key,INT_T size,SQUserPointer * typetag) {
293 BOOL_T SquirrelObject::GetUserData(
const SQChar * key,SQUserPointer * data,SQUserPointer * typetag) {
297 sq_pop(SquirrelVM::_VM,1);
300 sq_pop(SquirrelVM::_VM,1);
304 BOOL_T SquirrelObject::RawGetUserData(
const SQChar * key,SQUserPointer * data,SQUserPointer * typetag) {
306 if (RawGetSlot(key)) {
308 sq_pop(SquirrelVM::_VM,1);
311 sq_pop(SquirrelVM::_VM,1);
319 BOOL_T SquirrelObject::ArrayResize(INT_T newSize) {
323 sq_pop(SquirrelVM::_VM,1);
328 BOOL_T SquirrelObject::ArrayExtend(INT_T amount) {
329 SQInteger newLen = Len()+amount;
330 return ArrayResize(newLen);
333 BOOL_T SquirrelObject::ArrayReverse(
void) {
336 sq_pop(SquirrelVM::_VM,1);
340 SquirrelObject SquirrelObject::ArrayPop(SQBool returnPoppedVal) {
342 SQInteger top =
sq_gettop(SquirrelVM::_VM);
344 if (
sq_arraypop(SquirrelVM::_VM,-1,returnPoppedVal) == SQ_OK) {
345 if (returnPoppedVal) {
346 ret.AttachToStackObject(-1);
355 SQObjectType SquirrelObject::GetType()
360 BOOL_T SquirrelObject::GetSlot(INT_T key)
const 364 if(SQ_SUCCEEDED(
sq_get(SquirrelVM::_VM,-2))) {
372 SquirrelObject SquirrelObject::GetValue(INT_T key)
const 376 ret.AttachToStackObject(-1);
377 sq_pop(SquirrelVM::_VM,1);
379 sq_pop(SquirrelVM::_VM,1);
383 FLOAT_T SquirrelObject::GetFloat(INT_T key)
const 388 sq_pop(SquirrelVM::_VM,1);
390 sq_pop(SquirrelVM::_VM,1);
394 INT_T SquirrelObject::GetInt(INT_T key)
const 399 sq_pop(SquirrelVM::_VM,1);
401 sq_pop(SquirrelVM::_VM,1);
405 const SQChar *SquirrelObject::GetString(INT_T key)
const 410 sq_pop(SquirrelVM::_VM,1);
412 sq_pop(SquirrelVM::_VM,1);
416 bool SquirrelObject::GetBool(INT_T key)
const 421 sq_pop(SquirrelVM::_VM,1);
423 sq_pop(SquirrelVM::_VM,1);
424 return ret?
true:
false;
427 BOOL_T SquirrelObject::Exists(
const SQChar *key)
const 433 sq_pop(SquirrelVM::_VM,1);
439 BOOL_T SquirrelObject::GetSlot(
const SQChar *name)
const 443 if(SQ_SUCCEEDED(
sq_get(SquirrelVM::_VM,-2))) {
450 BOOL_T SquirrelObject::RawGetSlot(
const SQChar *name)
const {
453 if(SQ_SUCCEEDED(
sq_rawget(SquirrelVM::_VM,-2))) {
459 SquirrelObject SquirrelObject::GetValue(
const SQChar *key)
const 463 ret.AttachToStackObject(-1);
464 sq_pop(SquirrelVM::_VM,1);
466 sq_pop(SquirrelVM::_VM,1);
470 FLOAT_T SquirrelObject::GetFloat(
const SQChar *key)
const 475 sq_pop(SquirrelVM::_VM,1);
477 sq_pop(SquirrelVM::_VM,1);
481 INT_T SquirrelObject::GetInt(
const SQChar *key)
const 486 sq_pop(SquirrelVM::_VM,1);
488 sq_pop(SquirrelVM::_VM,1);
492 const SQChar *SquirrelObject::GetString(
const SQChar *key)
const 497 sq_pop(SquirrelVM::_VM,1);
499 sq_pop(SquirrelVM::_VM,1);
503 bool SquirrelObject::GetBool(
const SQChar *key)
const 508 sq_pop(SquirrelVM::_VM,1);
510 sq_pop(SquirrelVM::_VM,1);
511 return ret?
true:
false;
514 SQUserPointer SquirrelObject::GetInstanceUP(SQUserPointer tag)
const 518 if (SQ_FAILED(
sq_getinstanceup(SquirrelVM::_VM,-1,(SQUserPointer*)&up,tag))) {
522 sq_pop(SquirrelVM::_VM,1);
526 BOOL_T SquirrelObject::SetInstanceUP(SQUserPointer up)
528 if(!sq_isinstance(_o))
return FALSE;
531 sq_pop(SquirrelVM::_VM,1);
535 SquirrelObject SquirrelObject::GetAttributes(
const SQChar *key)
538 SQInteger top =
sq_gettop(SquirrelVM::_VM);
545 ret.AttachToStackObject(-1);
551 BOOL_T SquirrelObject::BeginIteration()
553 if(!sq_istable(_o) && !sq_isarray(_o) && !sq_isclass(_o))
560 BOOL_T SquirrelObject::Next(SquirrelObject &key,SquirrelObject &val)
562 if(SQ_SUCCEEDED(
sq_next(SquirrelVM::_VM,-2))) {
563 key.AttachToStackObject(-2);
564 val.AttachToStackObject(-1);
565 sq_pop(SquirrelVM::_VM,2);
571 BOOL_T SquirrelObject::GetTypeTag(SQUserPointer * typeTag) {
581 SqPlus::ScriptStringVar256 varNameTag;
582 SqPlus::getVarNameTag(varNameTag,
sizeof(varNameTag),key);
583 SQUserPointer data=0;
584 if (!RawGetUserData(varNameTag,&data)) {
587 SqPlus::VarRefPtr vr = (SqPlus::VarRefPtr)data;
589 #else // This version will only work if SQ_SUPPORT_INSTANCE_TYPE_INFO is enabled. 590 SquirrelObject so = GetValue(key);
591 if (so.IsNull())
return NULL;
592 return so.GetTypeName();
597 SquirrelObject so = GetValue(key);
598 if (so.IsNull())
return NULL;
599 return so.GetTypeName();
603 SQUserPointer typeTag=
NULL;
605 SquirrelObject typeTable = SquirrelVM::GetRootTable().GetValue(SQ_PLUS_TYPE_TABLE);
606 if (typeTable.IsNull()) {
609 return typeTable.GetString(INT_T((
size_t)typeTag));
614 const SQChar* SquirrelObject::ToString()
619 SQInteger SquirrelObject::ToInteger()
624 SQFloat SquirrelObject::ToFloat()
629 bool SquirrelObject::ToBool()
632 return _o._unVal.nInteger?
true:
false;
635 void SquirrelObject::EndIteration()
637 sq_pop(SquirrelVM::_VM,2);
SQRESULT sq_get(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_arraypop(HSQUIRRELVM v, SQInteger idx, SQBool pushval)
SQRESULT sq_rawget(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p, SQUserPointer typetag)
SQRESULT sq_clone(HSQUIRRELVM v, SQInteger idx)
void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
SQRESULT sq_getuserdata(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p, SQUserPointer *typetag)
SQInteger IsNull(HSQUIRRELVM v)
SQRESULT sq_rawset(HSQUIRRELVM v, SQInteger idx)
void sq_pushnull(HSQUIRRELVM v)
void SetValue(WatchesProperty *prop)
SQRESULT sq_arrayappend(HSQUIRRELVM v, SQInteger idx)
void sq_pushfloat(HSQUIRRELVM v, SQFloat n)
SQRESULT sq_getinteger(HSQUIRRELVM v, SQInteger idx, SQInteger *i)
SQInteger sq_getsize(HSQUIRRELVM v, SQInteger idx)
const SQChar * GetTypeName(const SQObjectPtr &obj1)
SQInteger sq_gettop(HSQUIRRELVM v)
#define _SETVALUE_INT_BEGIN
void sq_pushinteger(HSQUIRRELVM v, SQInteger n)
SQRESULT sq_next(HSQUIRRELVM v, SQInteger idx)
#define _SETVALUE_INT_END
#define _SETVALUE_STR_END
SQBool sq_release(HSQUIRRELVM v, HSQOBJECT *po)
void sq_settop(HSQUIRRELVM v, SQInteger newtop)
void sq_reseterror(HSQUIRRELVM v)
SQRESULT sq_arrayresize(HSQUIRRELVM v, SQInteger idx, SQInteger newsize)
SQRESULT sq_getfloat(HSQUIRRELVM v, SQInteger idx, SQFloat *f)
SQRESULT sq_getattributes(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_getobjtypetag(HSQOBJECT *o, SQUserPointer *typetag)
void sq_pushstring(HSQUIRRELVM v, const SQChar *s, SQInteger len)
SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p)
SQRESULT sq_getstring(HSQUIRRELVM v, SQInteger idx, const SQChar **c)
const SQChar * sq_objtostring(HSQOBJECT *o)
SQRESULT sq_getuserpointer(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p)
SQRESULT sq_getbool(HSQUIRRELVM v, SQInteger idx, SQBool *b)
void sq_resetobject(HSQOBJECT *po)
SQUserPointer sq_newuserdata(HSQUIRRELVM v, SQUnsignedInteger size)
SQRESULT sq_settypetag(HSQUIRRELVM v, SQInteger idx, SQUserPointer typetag)
void sq_pushbool(HSQUIRRELVM v, SQBool b)
void sq_addref(HSQUIRRELVM v, HSQOBJECT *po)
SQInteger sq_objtointeger(HSQOBJECT *o)
SQRESULT sq_arrayreverse(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_getdelegate(HSQUIRRELVM v, SQInteger idx)
SQRESULT sq_getstackobj(HSQUIRRELVM v, SQInteger idx, HSQOBJECT *po)
SQRESULT sq_setdelegate(HSQUIRRELVM v, SQInteger idx)
void sq_pushobject(HSQUIRRELVM v, HSQOBJECT obj)
SQFloat sq_objtofloat(HSQOBJECT *o)
void sq_pushuserpointer(HSQUIRRELVM v, SQUserPointer p)
#define _SETVALUE_STR_BEGIN