28 #if !defined(_SCRAT_TYPES_H_)
29 #define _SCRAT_TYPES_H_
39 #include "sqratClassType.h"
40 #include "sqratUtil.h"
47 template <
typename T1,
typename T2>
51 struct True_ {
char x[2]; };
54 static True_ helper(T2
const &);
55 static False_ helper(...);
60 static bool const YES = (
61 sizeof(True_) ==
sizeof(is_convertible::helper(*dummy))
65 template <
typename T,
bool b>
69 popAsInt(HSQUIRRELVM vm, SQInteger idx)
71 SQObjectType value_type = sq_gettype(vm, idx);
75 sq_getbool(vm, idx, &sqValueb);
76 value =
static_cast<T
>(sqValueb);
80 sq_getinteger(vm, idx, &sqValue);
81 value =
static_cast<T
>(sqValue);
85 sq_getfloat(vm, idx, &sqValuef);
86 value =
static_cast<T
>(sqValuef);
89 #if !defined (SCRAT_NO_ERROR_CHECKING)
92 value =
static_cast<T
>(0);
99 struct popAsInt<T, false>
102 popAsInt(HSQUIRRELVM , SQInteger )
108 template <
typename T>
112 popAsFloat(HSQUIRRELVM vm, SQInteger idx)
114 SQObjectType value_type = sq_gettype(vm, idx);
118 sq_getbool(vm, idx, &sqValueb);
119 value =
static_cast<T
>(sqValueb);
123 sq_getinteger(vm, idx, &sqValue);
124 value =
static_cast<T
>(sqValue);
128 sq_getfloat(vm, idx, &sqValuef);
129 value =
static_cast<T
>(sqValuef);
132 #if !defined (SCRAT_NO_ERROR_CHECKING)
164 Var(HSQUIRRELVM vm, SQInteger idx) {
165 #if !defined (SCRAT_NO_ERROR_CHECKING)
170 T* ptr = ClassType<T>::GetInstance(vm, idx);
173 #if !defined (SCRAT_NO_ERROR_CHECKING)
174 }
else if (is_convertible<T, SQInteger>::YES) {
176 value = popAsInt<T, is_convertible<T, SQInteger>::YES>(vm, idx).
value;
179 value = popAsInt<T, is_convertible<T, SQInteger>::YES>(vm, idx).
value;
183 value = popAsInt<T, is_convertible<T, SQInteger>::YES>(vm, idx).
value;
194 if (ClassType<T>::hasClassTypeData(vm))
195 ClassType<T>::PushInstanceCopy(vm, value);
197 pushAsInt<T, is_convertible<T, SQInteger>::YES>().
push(vm, (value));
201 template <
class T2,
bool b>
203 void push(HSQUIRRELVM vm,
const T2& ) {
209 struct pushAsInt<T2, true> {
210 void push(HSQUIRRELVM vm,
const T2&
value) {
211 sq_pushinteger(vm, static_cast<SQInteger>(value));
237 Var(HSQUIRRELVM vm, SQInteger idx) : value(*ClassType<T>::GetInstance(vm, idx)) {
247 static void push(HSQUIRRELVM vm, T& value) {
248 ClassType<T>::PushInstance(vm, &value);
273 Var(HSQUIRRELVM vm, SQInteger idx) : value(ClassType<T>::GetInstance(vm, idx)) {
283 static void push(HSQUIRRELVM vm, T* value) {
284 ClassType<T>::PushInstance(vm, value);
309 Var(HSQUIRRELVM vm, SQInteger idx) : value(ClassType<T>::GetInstance(vm, idx)) {
319 static void push(HSQUIRRELVM vm, T*
const value) {
320 ClassType<T>::PushInstance(vm, value);
345 Var(HSQUIRRELVM vm, SQInteger idx) : value(*ClassType<T>::GetInstance(vm, idx)) {
355 static void push(HSQUIRRELVM vm,
const T& value) {
356 ClassType<T>::PushInstanceCopy(vm, value);
381 Var(HSQUIRRELVM vm, SQInteger idx) : value(ClassType<T>::GetInstance(vm, idx)) {
391 static void push(HSQUIRRELVM vm,
const T* value) {
392 ClassType<T>::PushInstance(vm, const_cast<T*>(value));
403 struct Var<const T*
const> {
417 Var(HSQUIRRELVM vm, SQInteger idx) : value(ClassType<T>::GetInstance(vm, idx)) {
427 static void push(HSQUIRRELVM vm,
const T*
const value) {
428 ClassType<T>::PushInstance(vm, const_cast<T*>(value));
453 Var(HSQUIRRELVM vm, SQInteger idx) {
455 #if !defined (SCRAT_NO_ERROR_CHECKING)
458 value.Init(
new T(instance));
459 #if !defined (SCRAT_NO_ERROR_CHECKING)
472 PushVarR(vm, value.
Get());
477 #define SCRAT_INTEGER( type ) \
481 Var(HSQUIRRELVM vm, SQInteger idx) { \
482 value = popAsInt<type, true>(vm, idx).value; \
484 static void push(HSQUIRRELVM vm, const type& value) { \
485 sq_pushinteger(vm, static_cast<SQInteger>(value)); \
490 struct Var<const type> { \
492 Var(HSQUIRRELVM vm, SQInteger idx) { \
493 value = popAsInt<type, true>(vm, idx).value; \
495 static void push(HSQUIRRELVM vm, const type& value) { \
496 sq_pushinteger(vm, static_cast<SQInteger>(value)); \
501 struct Var<const type&> { \
503 Var(HSQUIRRELVM vm, SQInteger idx) { \
504 value = popAsInt<type, true>(vm, idx).value; \
506 static void push(HSQUIRRELVM vm, const type& value) { \
507 sq_pushinteger(vm, static_cast<SQInteger>(value)); \
511 SCRAT_INTEGER(
unsigned int)
512 SCRAT_INTEGER(
signed int)
513 SCRAT_INTEGER(
unsigned long)
514 SCRAT_INTEGER(
signed long)
515 SCRAT_INTEGER(
unsigned short)
516 SCRAT_INTEGER(
signed short)
517 SCRAT_INTEGER(
unsigned char)
518 SCRAT_INTEGER(
signed char)
519 SCRAT_INTEGER(
unsigned long long)
520 SCRAT_INTEGER(
signed long long)
524 SCRAT_INTEGER(
unsigned __int64)
525 SCRAT_INTEGER(
signed __int64)
530 #define SCRAT_FLOAT( type ) \
534 Var(HSQUIRRELVM vm, SQInteger idx) { \
535 value = popAsFloat<type>(vm, idx).value; \
537 static void push(HSQUIRRELVM vm, const type& value) { \
538 sq_pushfloat(vm, static_cast<SQFloat>(value)); \
543 struct Var<const type> { \
545 Var(HSQUIRRELVM vm, SQInteger idx) { \
546 value = popAsFloat<type>(vm, idx).value; \
548 static void push(HSQUIRRELVM vm, const type& value) { \
549 sq_pushfloat(vm, static_cast<SQFloat>(value)); \
553 struct Var<const type&> { \
555 Var(HSQUIRRELVM vm, SQInteger idx) { \
556 value = popAsFloat<type>(vm, idx).value; \
558 static void push(HSQUIRRELVM vm, const type& value) { \
559 sq_pushfloat(vm, static_cast<SQFloat>(value)); \
581 Var(HSQUIRRELVM vm, SQInteger idx) {
583 sq_tobool(vm, idx, &sqValue);
584 value = (sqValue != 0);
594 static void push(HSQUIRRELVM vm,
const bool& value) {
595 sq_pushbool(vm, static_cast<SQBool>(value));
614 Var(HSQUIRRELVM vm, SQInteger idx) {
616 sq_tobool(vm, idx, &sqValue);
617 value = (sqValue != 0);
628 sq_pushbool(vm, static_cast<SQBool>(value));
647 Var(HSQUIRRELVM vm, SQInteger idx) {
649 sq_tobool(vm, idx, &sqValue);
650 value = (sqValue != 0);
660 static void push(HSQUIRRELVM vm,
const bool& value) {
661 sq_pushbool(vm, static_cast<SQBool>(value));
686 Var(HSQUIRRELVM vm, SQInteger idx) {
687 sq_tostring(vm, idx);
688 sq_getstackobj(vm, -1, &obj);
689 sq_getstring(vm, -1, (
const SQChar**)&value);
701 if(v && !sq_isnull(obj)) {
713 static void push(HSQUIRRELVM vm,
const SQChar* value) {
714 sq_pushstring(vm, value, -1);
722 struct Var<const SQChar*> {
739 Var(HSQUIRRELVM vm, SQInteger idx) {
740 sq_tostring(vm, idx);
741 sq_getstackobj(vm, -1, &obj);
742 sq_getstring(vm, -1, &value);
754 if(v && !sq_isnull(obj)) {
766 static void push(HSQUIRRELVM vm,
const SQChar* value) {
767 sq_pushstring(vm, value, -1);
786 Var(HSQUIRRELVM vm, SQInteger idx) {
788 sq_tostring(vm, idx);
789 sq_getstring(vm, -1, &ret);
801 static void push(HSQUIRRELVM vm,
const string &
value) {
802 sq_pushstring(vm, value.c_str(), -1);
821 Var(HSQUIRRELVM vm, SQInteger idx) {
823 sq_tostring(vm, idx);
824 sq_getstring(vm, -1, &ret);
836 static void push(HSQUIRRELVM vm,
const string & value) {
837 sq_pushstring(vm, value.c_str(), -1);
845 struct Var<const string&> {
856 Var(HSQUIRRELVM vm, SQInteger idx) {
858 sq_tostring(vm, idx);
859 sq_getstring(vm, -1, &ret);
871 static void push(HSQUIRRELVM vm,
const string & value) {
872 sq_pushstring(vm, value.c_str(), -1);
881 struct Var<std::string> {
892 Var(HSQUIRRELVM vm, SQInteger idx) {
894 sq_tostring(vm, idx);
895 sq_getstring(vm, -1, &ret);
896 value = wstring_to_string(
string(ret));
907 static void push(HSQUIRRELVM vm,
const std::string &
value) {
908 sq_pushstring(vm, string_to_wstring(value).c_str(), -1);
916 struct Var<std::string&> {
927 Var(HSQUIRRELVM vm, SQInteger idx) {
929 sq_tostring(vm, idx);
930 sq_getstring(vm, -1, &ret);
931 value = wstring_to_string(
string(ret));
942 static void push(HSQUIRRELVM vm,
const std::string & value) {
943 sq_pushstring(vm, string_to_wstring(value).c_str(), -1);
951 struct Var<const std::string&> {
962 Var(HSQUIRRELVM vm, SQInteger idx) {
964 sq_tostring(vm, idx);
965 sq_getstring(vm, -1, &ret);
966 value = wstring_to_string(
string(ret));
977 static void push(HSQUIRRELVM vm,
const std::string & value) {
978 sq_pushstring(vm, string_to_wstring(value).c_str(), -1);
1003 Var(HSQUIRRELVM vm, SQInteger idx) {
1006 sq_tostring(vm, idx);
1007 sq_getstackobj(vm, -1, &obj);
1008 sq_getstring(vm, -1, &sv);
1009 sq_addref(vm, &obj);
1012 holder = wstring_to_string(
string(sv));
1013 value = strdup(holder.c_str());
1022 if(v && !sq_isnull(obj)) {
1023 sq_release(v, &obj);
1035 static void push(HSQUIRRELVM vm,
const char* value) {
1036 sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), -1);
1044 struct Var<const char*> {
1061 Var(HSQUIRRELVM vm, SQInteger idx) {
1064 sq_tostring(vm, idx);
1065 sq_getstackobj(vm, -1, &obj);
1066 sq_getstring(vm, -1, &sv);
1067 sq_addref(vm, &obj);
1070 holder = wstring_to_string(
string(sv));
1071 value = strdup(holder.c_str());
1080 if(v && !sq_isnull(obj)) {
1081 sq_release(v, &obj);
1093 static void push(HSQUIRRELVM vm,
const char* value) {
1094 sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), -1);
1113 inline void PushVar(HSQUIRRELVM vm, T value) {
1122 inline void PushVar<int>(HSQUIRRELVM vm,
int value) {
1141 inline void PushVarR(HSQUIRRELVM vm, T & value) {
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:821
static void push(HSQUIRRELVM vm, SharedPtr< T > value)
Definition: sqratTypes.h:471
string value
The actual value of get operations.
Definition: sqratTypes.h:847
bool value
The actual value of get operations.
Definition: sqratTypes.h:605
static void push(HSQUIRRELVM vm, const T &value)
Definition: sqratTypes.h:193
static void push(HSQUIRRELVM vm, const string &value)
Definition: sqratTypes.h:871
T value
The actual value of get operations.
Definition: sqratTypes.h:152
static void push(HSQUIRRELVM vm, T *const value)
Definition: sqratTypes.h:319
~Var()
Definition: sqratTypes.h:699
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:345
static void push(HSQUIRRELVM vm, const string &value)
Definition: sqratTypes.h:836
Definition: sqratTypes.h:150
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:614
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:686
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:309
T * Get() const
Definition: sqratUtil.h:665
static void push(HSQUIRRELVM vm, T &value)
Definition: sqratTypes.h:247
static string FormatTypeError(HSQUIRRELVM vm, SQInteger idx, const string &expectedType)
Definition: sqratUtil.h:149
void Clear(HSQUIRRELVM vm)
Definition: sqratUtil.h:170
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:381
static void push(HSQUIRRELVM vm, const SQChar *value)
Definition: sqratTypes.h:766
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:581
static void push(HSQUIRRELVM vm, const bool &value)
Definition: sqratTypes.h:594
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:647
Definition: sqratTypes.h:331
T & value
The actual value of get operations.
Definition: sqratTypes.h:225
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:856
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:739
static void push(HSQUIRRELVM vm, const T *const value)
Definition: sqratTypes.h:427
static void push(HSQUIRRELVM vm, const string &value)
Definition: sqratTypes.h:801
Definition: sqratUtil.h:291
bool value
The actual value of get operations.
Definition: sqratTypes.h:638
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:453
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:164
const SQChar * value
The actual value of get operations.
Definition: sqratTypes.h:730
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:273
string value
The actual value of get operations.
Definition: sqratTypes.h:777
T * value
The actual value of get operations.
Definition: sqratTypes.h:261
static Error & Instance()
Definition: sqratUtil.h:134
void Throw(HSQUIRRELVM vm, const string &err)
Definition: sqratUtil.h:210
const T & value
The actual value of get operations.
Definition: sqratTypes.h:333
const T *const value
The actual value of get operations.
Definition: sqratTypes.h:405
static void push(HSQUIRRELVM vm, const bool &value)
Definition: sqratTypes.h:627
static void push(HSQUIRRELVM vm, const T &value)
Definition: sqratTypes.h:355
const T * value
The actual value of get operations.
Definition: sqratTypes.h:369
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:417
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:237
static void push(HSQUIRRELVM vm, const bool &value)
Definition: sqratTypes.h:660
bool value
The actual value of get operations.
Definition: sqratTypes.h:572
static void push(HSQUIRRELVM vm, const SQChar *value)
Definition: sqratTypes.h:713
SQChar * value
The actual value of get operations.
Definition: sqratTypes.h:677
Var(HSQUIRRELVM vm, SQInteger idx)
Definition: sqratTypes.h:786
static void push(HSQUIRRELVM vm, T *value)
Definition: sqratTypes.h:283
static void push(HSQUIRRELVM vm, const T *value)
Definition: sqratTypes.h:391
string value
The actual value of get operations.
Definition: sqratTypes.h:812
~Var()
Definition: sqratTypes.h:752
SharedPtr< T > value
The actual value of get operations.
Definition: sqratTypes.h:441
T *const value
The actual value of get operations.
Definition: sqratTypes.h:297
bool Occurred(HSQUIRRELVM vm)
Definition: sqratUtil.h:198