28 #if !defined(_SCRAT_OBJECT_H_)
29 #define _SCRAT_OBJECT_H_
34 #include "sqratAllocator.h"
35 #include "sqratTypes.h"
36 #include "sqratOverloadMethods.h"
37 #include "sqratUtil.h"
55 Object(HSQUIRRELVM v,
bool releaseOnDestroy =
true) : vm(v), release(releaseOnDestroy) {
75 Object(
const Object& so) : vm(so.vm), obj(so.obj), release(so.release) {
101 ClassType<T>::PushInstance(vm, instance);
102 sq_getstackobj(vm, -1, &obj);
131 release = so.release;
200 operator HSQOBJECT&() {
209 sq_release(vm, &obj);
210 sq_resetobject(&obj);
224 sq_pushstring(vm, slot, -1);
226 #if !defined (SCRAT_NO_ERROR_CHECKING)
227 if(SQ_FAILED(sq_get(vm, -2))) {
231 sq_getstackobj(vm, -1, &slotObj);
238 sq_getstackobj(vm, -1, &slotObj);
256 sq_pushinteger(vm, index);
258 #if !defined (SCRAT_NO_ERROR_CHECKING)
259 if(SQ_FAILED(sq_get(vm, -2))) {
263 sq_getstackobj(vm, -1, &slotObj);
270 sq_getstackobj(vm, -1, &slotObj);
291 T ret =
Var<T>(vm, -1).value;
320 SQInteger ret = sq_getsize(vm, -1);
341 sq_resetobject(&Key);
342 sq_resetobject(&Value);
344 Value._type = OT_NULL;
379 sq_pushobject(vm,obj);
380 sq_pushinteger(vm,iter.Index);
381 if(SQ_SUCCEEDED(sq_next(vm,-2)))
383 sq_getstackobj(vm,-1,&iter.Value);
384 sq_getstackobj(vm,-2,&iter.Key);
385 sq_getinteger(vm,-3,&iter.Index);
400 inline void BindFunc(
const SQChar* name,
void* method,
size_t methodSize, SQFUNCTION func,
bool staticVar =
false) {
402 sq_pushstring(vm, name, -1);
404 SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
405 memcpy(methodPtr, method, methodSize);
407 sq_newclosure(vm, func, 1);
408 sq_newslot(vm, -3, staticVar);
412 inline void BindFunc(
const SQInteger index,
void* method,
size_t methodSize, SQFUNCTION func,
bool staticVar =
false) {
414 sq_pushinteger(vm, index);
416 SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
417 memcpy(methodPtr, method, methodSize);
419 sq_newclosure(vm, func, 1);
420 sq_newslot(vm, -3, staticVar);
426 inline void BindOverload(
const SQChar* name,
void* method,
size_t methodSize, SQFUNCTION func, SQFUNCTION overload,
int argCount,
bool staticVar =
false) {
427 string overloadName = SqOverloadName::Get(name, argCount);
432 sq_pushstring(vm, name, -1);
433 sq_pushstring(vm, name, -1);
434 sq_newclosure(vm, overload, 1);
435 sq_newslot(vm, -3, staticVar);
438 sq_pushstring(vm, overloadName.c_str(), -1);
439 SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
440 memcpy(methodPtr, method, methodSize);
441 sq_newclosure(vm, func, 1);
442 sq_newslot(vm, -3, staticVar);
449 inline void BindValue(
const SQChar* name,
const V& val,
bool staticVar =
false) {
451 sq_pushstring(vm, name, -1);
453 sq_newslot(vm, -3, staticVar);
457 inline void BindValue(
const SQInteger index,
const V& val,
bool staticVar =
false) {
459 sq_pushinteger(vm, index);
461 sq_newslot(vm, -3, staticVar);
467 inline void BindInstance(
const SQChar* name, V* val,
bool staticVar =
false) {
469 sq_pushstring(vm, name, -1);
471 sq_newslot(vm, -3, staticVar);
475 inline void BindInstance(
const SQInteger index, V* val,
bool staticVar =
false) {
477 sq_pushinteger(vm, index);
479 sq_newslot(vm, -3, staticVar);
488 inline void Object::BindValue<int>(
const SQChar* name,
const int & val,
bool staticVar ) {
489 sq_pushobject(vm, GetObject());
490 sq_pushstring(vm, name, -1);
491 PushVar<int>(vm, val);
492 sq_newslot(vm, -3, staticVar);
515 Var(HSQUIRRELVM vm, SQInteger idx) {
517 sq_getstackobj(vm, idx, &sqValue);
550 Var(HSQUIRRELVM vm, SQInteger idx) {
552 sq_getstackobj(vm, idx, &sqValue);
553 value =
Object(sqValue, vm);
static void push(HSQUIRRELVM vm, Object &value)
Definition: sqratObject.h:563
static HSQUIRRELVM Get()
Definition: sqratUtil.h:92
Object GetSlot(SQInteger index) const
Definition: sqratObject.h:253
void Release()
Definition: sqratObject.h:208
Object value
The actual value of get operations.
Definition: sqratObject.h:538
HSQOBJECT getKey()
Definition: sqratObject.h:353
SQObjectType GetType() const
Definition: sqratObject.h:162
T value
The actual value of get operations.
Definition: sqratTypes.h:152
HSQOBJECT getValue()
Definition: sqratObject.h:361
Object value
The actual value of get operations.
Definition: sqratObject.h:503
Definition: sqratTypes.h:150
T Cast() const
Definition: sqratObject.h:289
Object(HSQOBJECT o, HSQUIRRELVM v=DefaultVM::Get())
Definition: sqratObject.h:86
bool IsNull() const
Definition: sqratObject.h:172
SQInteger GetSize() const
Definition: sqratObject.h:318
iterator()
Definition: sqratObject.h:338
Object(const Object &so)
Definition: sqratObject.h:75
HSQUIRRELVM GetVM() const
Definition: sqratObject.h:152
Object GetSlot(const SQChar *slot) const
Definition: sqratObject.h:221
Object & operator=(const Object &so)
Definition: sqratObject.h:125
virtual HSQOBJECT GetObject() const
Definition: sqratObject.h:182
Object()
Definition: sqratObject.h:65
static void push(HSQUIRRELVM vm, Object &value)
Definition: sqratObject.h:528
Object(T *instance, HSQUIRRELVM v=DefaultVM::Get())
Definition: sqratObject.h:100
bool Next(iterator &iter) const
Definition: sqratObject.h:377
virtual HSQOBJECT & GetObject()
Definition: sqratObject.h:192
Definition: sqratObject.h:48
virtual ~Object()
Definition: sqratObject.h:110
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratObject.h:515
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratObject.h:550
Iterator for going over the slots in the object using Object::Next.
Definition: sqratObject.h:328
HSQUIRRELVM & GetVM()
Definition: sqratObject.h:142
Object operator[](T slot)
Definition: sqratObject.h:307