summaryrefslogtreecommitdiffstats
path: root/squirrel_3_0_1_stable/sqplus/SquirrelObject.cpp
blob: 58d43bbed307cbb78b42804eb04c929635d22a95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#include "sqplus.h"

SquirrelObject::SquirrelObject(void)
{
	 sq_resetobject(&_o);
}

SquirrelObject::~SquirrelObject()
{
    Reset();
}

SquirrelObject::SquirrelObject(const SquirrelObject &o)
{
	_o = o._o;
	sq_addref(SquirrelVM::_VM,&_o);
}

SquirrelObject::SquirrelObject(HSQOBJECT o)
{
	_o = o;
	sq_addref(SquirrelVM::_VM,&_o);
}

void SquirrelObject::Reset(void) {
  if(SquirrelVM::_VM)
    sq_release(SquirrelVM::_VM,&_o);
  else if( _o._type!=OT_NULL && _o._unVal.pRefCounted )
    printf( "SquirrelObject::~SquirrelObject - Cannot release\n" ); 
  sq_resetobject(&_o);
} // SquirrelObject::Reset

SquirrelObject SquirrelObject::Clone()
{
	SquirrelObject ret;
	if(GetType() == OT_TABLE || GetType() == OT_ARRAY)
	{
		sq_pushobject(SquirrelVM::_VM,_o);
		sq_clone(SquirrelVM::_VM,-1);
		ret.AttachToStackObject(-1);
		sq_pop(SquirrelVM::_VM,2);
	}
	return ret;

}

SquirrelObject & SquirrelObject::operator =(const SquirrelObject &o)
{
	//HSQOBJECT t;
	//t = o._o;
	//sq_addref(SquirrelVM::_VM,&t);
	sq_addref(SquirrelVM::_VM, (HSQOBJECT*)&o._o);
	sq_release(SquirrelVM::_VM,&_o);
	//_o = t;
	_o = o._o;
	return *this;
}

SquirrelObject & SquirrelObject::operator =(HSQOBJECT ho)
{
	sq_addref(SquirrelVM::_VM,&ho);
	sq_release(SquirrelVM::_VM,&_o);
	_o = ho;
	return *this;
}

SquirrelObject & SquirrelObject::operator =(int n)
{
	sq_pushinteger(SquirrelVM::_VM,n);
	AttachToStackObject(-1);
	sq_pop(SquirrelVM::_VM,1);
	return *this;
}

#include <assert.h>
#include "../squirrel/sqstate.h"
#include "../squirrel/sqvm.h"

SquirrelObject & SquirrelObject::operator =(HSQUIRRELVM v)
{
    if( v && SquirrelVM::_VM ){
    	SquirrelVM::_VM->Push(v);
        AttachToStackObject(-1);
        sq_poptop(SquirrelVM::_VM);
    }
    else Reset();
	return *this;
}

bool SquirrelObject::operator == (const SquirrelObject &o)
{
    bool cmp = false;
    HSQUIRRELVM v = SquirrelVM::GetVMPtr();
    int oldtop = sq_gettop(v);
    
    sq_pushobject(v, GetObjectHandle());
    sq_pushobject(v, o.GetObjectHandle());
    if(sq_cmp(v) == 0)
        cmp = true;
   
    sq_settop(v, oldtop);
    return cmp;
}

bool SquirrelObject::CompareUserPointer( const SquirrelObject &o )
{
    if( _o._type == o.GetObjectHandle()._type )
        if( _o._unVal.pUserPointer == o.GetObjectHandle()._unVal.pUserPointer )
            return true;

    return false;
}

void SquirrelObject::ArrayAppend(const SquirrelObject &o)
{
	if(sq_isarray(_o)) {
		sq_pushobject(SquirrelVM::_VM,_o);
		sq_pushobject(SquirrelVM::_VM,o._o);
		sq_arrayappend(SquirrelVM::_VM,-2);
		sq_pop(SquirrelVM::_VM,1);
	}
}

void SquirrelObject::AttachToStackObject(int idx)
{
	HSQOBJECT t;
	sq_getstackobj(SquirrelVM::_VM,idx,&t);
	sq_addref(SquirrelVM::_VM,&t);
	sq_release(SquirrelVM::_VM,&_o);
	_o = t;
}

BOOL SquirrelObject::SetDelegate(SquirrelObject &obj)
{
	if(obj.GetType() == OT_TABLE ||
		obj.GetType() == OT_NULL) {
			switch(_o._type) {
				case OT_USERDATA:
				case OT_TABLE:
					sq_pushobject(SquirrelVM::_VM,_o);
					sq_pushobject(SquirrelVM::_VM,obj._o);
					if(SQ_SUCCEEDED(sq_setdelegate(SquirrelVM::_VM,-2))) {
					  sq_pop(SquirrelVM::_VM,1);
					  return TRUE;
					}
					sq_pop(SquirrelVM::_VM,1);
					break;
			}
	}
	return FALSE;
}

SquirrelObject SquirrelObject::GetDelegate()
{
	SquirrelObject ret;
	if(_o._type == OT_TABLE || _o._type == OT_USERDATA)
	{
    int top = sq_gettop(SquirrelVM::_VM);
		sq_pushobject(SquirrelVM::_VM,_o);
		sq_getdelegate(SquirrelVM::_VM,-1);
		ret.AttachToStackObject(-1);
    sq_settop(SquirrelVM::_VM,top);
//		sq_pop(SquirrelVM::_VM,2);
	}
	return ret;
}

BOOL SquirrelObject::IsNull() const
{
	return sq_isnull(_o);
}

BOOL SquirrelObject::IsNumeric() const
{
	return sq_isnumeric(_o);
}

int SquirrelObject::Len() const
{
	int ret = 0;
	if(sq_isarray(_o) || sq_istable(_o) || sq_isstring(_o)) {
		sq_pushobject(SquirrelVM::_VM,_o);
		ret = sq_getsize(SquirrelVM::_VM,-1);
		sq_pop(SquirrelVM::_VM,1);
	}
	return ret;
}

#define _SETVALUE_INT_BEGIN \
	BOOL ret = FALSE; \
	int top = sq_gettop(SquirrelVM::_VM); \
	sq_pushobject(SquirrelVM::_VM,_o); \
	sq_pushinteger(SquirrelVM::_VM,key);

#define _SETVALUE_INT_END \
	if(SQ_SUCCEEDED(sq_rawset(SquirrelVM::_VM,-3))) { \
		ret = TRUE; \
	} \
	sq_settop(SquirrelVM::_VM,top); \
	return ret;

BOOL SquirrelObject::SetValue(INT key,const SquirrelObject &val)
{
	_SETVALUE_INT_BEGIN
	sq_pushobject(SquirrelVM::_VM,val._o);
	_SETVALUE_INT_END
}

BOOL SquirrelObject::SetValue(INT key,INT n)
{
	_SETVALUE_INT_BEGIN
	sq_pushinteger(SquirrelVM::_VM,n);
	_SETVALUE_INT_END
}

BOOL SquirrelObject::SetValue(INT key,FLOAT f)
{
	_SETVALUE_INT_BEGIN
	sq_pushfloat(SquirrelVM::_VM,f);
	_SETVALUE_INT_END
}

BOOL SquirrelObject::SetValue(INT key,const SQChar *s)
{
	_SETVALUE_INT_BEGIN
	sq_pushstring(SquirrelVM::_VM,s,-1);
	_SETVALUE_INT_END
}

BOOL SquirrelObject::SetValue(INT key,bool b)
{
	_SETVALUE_INT_BEGIN
	sq_pushbool(SquirrelVM::_VM,b);
	_SETVALUE_INT_END
}

BOOL SquirrelObject::SetValue(const SquirrelObject &key,const SquirrelObject &val)
{
	BOOL ret = FALSE;
	int top = sq_gettop(SquirrelVM::_VM);
	sq_pushobject(SquirrelVM::_VM,_o);
	sq_pushobject(SquirrelVM::_VM,key._o);
	sq_pushobject(SquirrelVM::_VM,val._o);
	if(SQ_SUCCEEDED(sq_rawset(SquirrelVM::_VM,-3))) {
		ret = TRUE;
	}
	sq_settop(SquirrelVM::_VM,top);
	return ret;
}

#define _SETVALUE_STR_BEGIN \
	BOOL ret = FALSE; \
	int top = sq_gettop(SquirrelVM::_VM); \
	sq_pushobject(SquirrelVM::_VM,_o); \
	sq_pushstring(SquirrelVM::_VM,key,-1);

#define _SETVALUE_STR_END \
	if(SQ_SUCCEEDED(sq_rawset(SquirrelVM::_VM,-3))) { \
		ret = TRUE; \
	} \
	sq_settop(SquirrelVM::_VM,top); \
	return ret;

BOOL SquirrelObject::SetValue(const SQChar *key,const SquirrelObject &val)
{
	_SETVALUE_STR_BEGIN
	sq_pushobject(SquirrelVM::_VM,val._o);
	_SETVALUE_STR_END
}

BOOL SquirrelObject::SetValue(const SQChar *key,INT n)
{
	_SETVALUE_STR_BEGIN
	sq_pushinteger(SquirrelVM::_VM,n);
	_SETVALUE_STR_END
}

BOOL SquirrelObject::SetValue(const SQChar *key,FLOAT f)
{
	_SETVALUE_STR_BEGIN
	sq_pushfloat(SquirrelVM::_VM,f);
	_SETVALUE_STR_END
}

BOOL SquirrelObject::SetValue(const SQChar *key,const SQChar *s)
{
	_SETVALUE_STR_BEGIN
	sq_pushstring(SquirrelVM::_VM,s,-1);
	_SETVALUE_STR_END
}

BOOL SquirrelObject::SetValue(const SQChar *key,bool b)
{
	_SETVALUE_STR_BEGIN
	sq_pushbool(SquirrelVM::_VM,b);
	_SETVALUE_STR_END
}

// === BEGIN User Pointer, User Data ===

BOOL SquirrelObject::SetUserPointer(const SQChar * key,SQUserPointer up) {
  _SETVALUE_STR_BEGIN
  sq_pushuserpointer(SquirrelVM::_VM,up);
  _SETVALUE_STR_END
} // SquirrelObject::SetUserPointer

SQUserPointer SquirrelObject::GetUserPointer(const SQChar * key) {
  SQUserPointer ret = NULL;
  if (GetSlot(key)) {
    sq_getuserpointer(SquirrelVM::_VM,-1,&ret);
    sq_pop(SquirrelVM::_VM,1);
  } // if
  sq_pop(SquirrelVM::_VM,1);
  return ret;
} // SquirrelObject::GetUserPointer

BOOL SquirrelObject::SetUserPointer(INT key,SQUserPointer up) {
  _SETVALUE_INT_BEGIN
  sq_pushuserpointer(SquirrelVM::_VM,up);
  _SETVALUE_INT_END
} // SquirrelObject::SetUserPointer

SQUserPointer SquirrelObject::GetUserPointer(INT key) {
  SQUserPointer ret = NULL;
  if (GetSlot(key)) {
    sq_getuserpointer(SquirrelVM::_VM,-1,&ret);
    sq_pop(SquirrelVM::_VM,1);
  } // if
  sq_pop(SquirrelVM::_VM,1);
  return ret;
} // SquirrelObject::GetUserPointer

// === User Data ===

BOOL SquirrelObject::NewUserData(const SQChar * key,INT size,SQUserPointer * typetag) {
  _SETVALUE_STR_BEGIN
  sq_newuserdata(SquirrelVM::_VM,size);
  if (typetag) {
    sq_settypetag(SquirrelVM::_VM,-1,typetag);
  } // if
  _SETVALUE_STR_END
} // SquirrelObject::NewUserData

BOOL SquirrelObject::GetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag) {
  BOOL ret = false;
  if (GetSlot(key)) {
    sq_getuserdata(SquirrelVM::_VM,-1,data,typetag);
    sq_pop(SquirrelVM::_VM,1);
    ret = true;
  } // if
  sq_pop(SquirrelVM::_VM,1);
  return ret;
} // SquirrelObject::GetUserData

BOOL SquirrelObject::RawGetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag) {
  BOOL ret = false;
  if (RawGetSlot(key)) {
    sq_getuserdata(SquirrelVM::_VM,-1,data,typetag);
    sq_pop(SquirrelVM::_VM,1);
    ret = true;
  } // if
  sq_pop(SquirrelVM::_VM,1);
  return ret;
} // SquirrelObject::RawGetUserData

// === END User Pointer ===

// === BEGIN Arrays ===

BOOL SquirrelObject::ArrayResize(INT newSize) {
//  int top = sq_gettop(SquirrelVM::_VM);
  sq_pushobject(SquirrelVM::_VM,GetObjectHandle());
  BOOL res = sq_arrayresize(SquirrelVM::_VM,-1,newSize) == SQ_OK;
  sq_pop(SquirrelVM::_VM,1);
//  sq_settop(SquirrelVM::_VM,top);
  return res;
} // SquirrelObject::ArrayResize

BOOL SquirrelObject::ArrayExtend(INT amount) {
  int newLen = Len()+amount;
  return ArrayResize(newLen);
} // SquirrelObject::ArrayExtend

BOOL SquirrelObject::ArrayReverse(void) {
  sq_pushobject(SquirrelVM::_VM,GetObjectHandle());
  BOOL res = sq_arrayreverse(SquirrelVM::_VM,-1) == SQ_OK;
  sq_pop(SquirrelVM::_VM,1);
  return res;
} // SquirrelObject::ArrayReverse

SquirrelObject SquirrelObject::ArrayPop(SQBool returnPoppedVal) {
  SquirrelObject ret;
  int top = sq_gettop(SquirrelVM::_VM);
  sq_pushobject(SquirrelVM::_VM,GetObjectHandle());
  if (sq_arraypop(SquirrelVM::_VM,-1,returnPoppedVal) == SQ_OK) {
    if (returnPoppedVal) {
      ret.AttachToStackObject(-1);
    } // if
  } // if
  sq_settop(SquirrelVM::_VM,top);
  return ret;
} // SquirrelObject::ArrayPop

// === END Arrays ===

SQObjectType SquirrelObject::GetType()
{
	return _o._type;
}

BOOL SquirrelObject::GetSlot(INT key) const
{
	sq_pushobject(SquirrelVM::_VM,_o);
	sq_pushinteger(SquirrelVM::_VM,key);
	if(SQ_SUCCEEDED(sq_get(SquirrelVM::_VM,-2))) {
		return TRUE;
	}
	
	return FALSE;
}


SquirrelObject SquirrelObject::GetValue(INT key)const
{
	SquirrelObject ret;
	if(GetSlot(key)) {
		ret.AttachToStackObject(-1);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

FLOAT SquirrelObject::GetFloat(INT key) const
{
	FLOAT ret = 0.0f;
	if(GetSlot(key)) {
		sq_getfloat(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

INT SquirrelObject::GetInt(INT key) const
{
	INT ret = 0;
	if(GetSlot(key)) {
		sq_getinteger(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

const SQChar *SquirrelObject::GetString(INT key) const
{
	const SQChar *ret = NULL;
	if(GetSlot(key)) {
		sq_getstring(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

bool SquirrelObject::GetBool(INT key) const
{
	SQBool ret = FALSE;
	if(GetSlot(key)) {
		sq_getbool(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret?true:false;
}

BOOL SquirrelObject::Exists(const SQChar *key) const
{
	if(GetSlot(key)) {
  	sq_pop(SquirrelVM::_VM,2);
		return TRUE;
	} else {
  	sq_pop(SquirrelVM::_VM,1);
		return FALSE;
	}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

BOOL SquirrelObject::GetSlot(const SQChar *name) const
{
	sq_pushobject(SquirrelVM::_VM,_o);
	sq_pushstring(SquirrelVM::_VM,name,-1);
	if(SQ_SUCCEEDED(sq_get(SquirrelVM::_VM,-2))) {
		return TRUE;
	}
	
	return FALSE;
}

BOOL SquirrelObject::RawGetSlot(const SQChar *name) const {
  sq_pushobject(SquirrelVM::_VM,_o);
  sq_pushstring(SquirrelVM::_VM,name,-1);
  if(SQ_SUCCEEDED(sq_rawget(SquirrelVM::_VM,-2))) {
    return TRUE;
  }
  return FALSE;
} // SquirrelObject::RawGetSlot

SquirrelObject SquirrelObject::GetValue(const SQChar *key)const
{
	SquirrelObject ret;
	if(GetSlot(key)) {
		ret.AttachToStackObject(-1);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

FLOAT SquirrelObject::GetFloat(const SQChar *key) const
{
	FLOAT ret = 0.0f;
	if(GetSlot(key)) {
		sq_getfloat(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

INT SquirrelObject::GetInt(const SQChar *key) const
{
	INT ret = 0;
	if(GetSlot(key)) {
		sq_getinteger(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

const SQChar *SquirrelObject::GetString(const SQChar *key) const
{
	const SQChar *ret = NULL;
	if(GetSlot(key)) {
		sq_getstring(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret;
}

bool SquirrelObject::GetBool(const SQChar *key) const
{
	SQBool ret = FALSE;
	if(GetSlot(key)) {
		sq_getbool(SquirrelVM::_VM,-1,&ret);
		sq_pop(SquirrelVM::_VM,1);
	}
	sq_pop(SquirrelVM::_VM,1);
	return ret?true:false;
}

SQUserPointer SquirrelObject::GetInstanceUP(SQUserPointer tag) const
{
    SQUserPointer up;
    sq_pushobject(SquirrelVM::_VM,_o);
    if (SQ_FAILED(sq_getinstanceup(SquirrelVM::_VM,-1,(SQUserPointer*)&up,tag))) {
        sq_reseterror(SquirrelVM::_VM);
        up = NULL;
    } // if
    sq_pop(SquirrelVM::_VM,1);
    return up;
}

BOOL SquirrelObject::SetInstanceUP(SQUserPointer up)
{
	if(!sq_isinstance(_o)) return FALSE;
	sq_pushobject(SquirrelVM::_VM,_o);
	sq_setinstanceup(SquirrelVM::_VM,-1,up);
	sq_pop(SquirrelVM::_VM,1);
	return TRUE;
}

SquirrelObject SquirrelObject::GetAttributes(const SQChar *key)
{
	SquirrelObject ret;
	int top = sq_gettop(SquirrelVM::_VM);
	sq_pushobject(SquirrelVM::_VM,_o);
	if(key)
		sq_pushstring(SquirrelVM::_VM,key,-1);
	else
		sq_pushnull(SquirrelVM::_VM);
	if(SQ_SUCCEEDED(sq_getattributes(SquirrelVM::_VM,-2))) {
		ret.AttachToStackObject(-1);
	}
	sq_settop(SquirrelVM::_VM,top);
	return ret;
}

BOOL SquirrelObject::BeginIteration()
{
	if(!sq_istable(_o) && !sq_isarray(_o) && !sq_isclass(_o))
		return FALSE;
	sq_pushobject(SquirrelVM::_VM,_o);
	sq_pushnull(SquirrelVM::_VM);
	return TRUE;
}

BOOL SquirrelObject::Next(SquirrelObject &key,SquirrelObject &val)
{
	if(SQ_SUCCEEDED(sq_next(SquirrelVM::_VM,-2))) {
		key.AttachToStackObject(-2);
		val.AttachToStackObject(-1);
		sq_pop(SquirrelVM::_VM,2);
		return TRUE;
	}
	return FALSE;
}

BOOL SquirrelObject::GetTypeTag(SQUserPointer * typeTag) {
  if (SQ_SUCCEEDED(sq_getobjtypetag(&_o,typeTag))) {
    return TRUE;
  } // if
  return FALSE;
} // SquirrelObject::GetTypeTag

const SQChar * SquirrelObject::GetTypeName(const SQChar * key) {
#if 1
  // This version will work even if SQ_SUPPORT_INSTANCE_TYPE_INFO is not enabled.
  SqPlus::ScriptStringVar256 varNameTag;
  SqPlus::getVarNameTag(varNameTag,sizeof(varNameTag),key);
  SQUserPointer data=0;
  if (!RawGetUserData(varNameTag,&data)) {
    return NULL;
  } // if
  SqPlus::VarRefPtr vr = (SqPlus::VarRefPtr)data;
  return vr->varType->GetTypeName();
#else // This version will only work if SQ_SUPPORT_INSTANCE_TYPE_INFO is enabled.
  SquirrelObject so = GetValue(key);
  if (so.IsNull()) return NULL;
  return so.GetTypeName();
#endif
} // SquirrelObject::GetTypeName

const SQChar * SquirrelObject::GetTypeName(INT key) {
  SquirrelObject so = GetValue(key);
  if (so.IsNull()) return NULL;
  return so.GetTypeName();
} // SquirrelObject::GetTypeName

const SQChar * SquirrelObject::GetTypeName(void) {
  SQUserPointer typeTag=NULL;
  if (SQ_SUCCEEDED(sq_getobjtypetag(&_o,&typeTag))) {
    SquirrelObject typeTable = SquirrelVM::GetRootTable().GetValue(SQ_PLUS_TYPE_TABLE);
    if (typeTable.IsNull()) {
      return NULL; // Not compiled with SQ_SUPPORT_INSTANCE_TYPE_INFO enabled.
    } // if
    return typeTable.GetString(INT((size_t)typeTag));
  } // if
  return NULL;
} // SquirrelObject::GetTypeName

SquirrelObject SquirrelObject::GetBase(void)
{
   SquirrelObject ret;
   sq_pushobject(SquirrelVM::_VM,_o);
   sq_getbase(SquirrelVM::_VM,-1);
   ret.AttachToStackObject(-1);
   sq_pop(SquirrelVM::_VM,2);

   return ret;
}

const SQChar* SquirrelObject::ToString()
{
	return sq_objtostring(&_o);
}

SQInteger SquirrelObject::ToInteger()
{
	return sq_objtointeger(&_o);
}

SQFloat SquirrelObject::ToFloat()
{
	return sq_objtofloat(&_o);
}

bool SquirrelObject::ToBool()
{
	//<<FIXME>>
	return _o._unVal.nInteger?true:false;
}

void SquirrelObject::EndIteration()
{
	sq_pop(SquirrelVM::_VM,2);
}