Utility library for providing native functionality to the Squirrel environment.
src/template.txt@0:a9a5c12f2d30, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 08:15:55 2014 +0000
- Revision:
- 0:a9a5c12f2d30
Initial import of sqbind 0.99
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:a9a5c12f2d30 | 1 | |
jhnwkmn | 0:a9a5c12f2d30 | 2 | template<class T,$class > |
jhnwkmn | 0:a9a5c12f2d30 | 3 | SQInteger _sqbind_sqmethod_$count(HSQUIRRELVM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 4 | |
jhnwkmn | 0:a9a5c12f2d30 | 5 | T* self = &SqBind<T>::get(v, 1 ); |
jhnwkmn | 0:a9a5c12f2d30 | 6 | typedef void (T::*M)($paramnames); |
jhnwkmn | 0:a9a5c12f2d30 | 7 | M*methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 8 | sq_getuserdata(v,-1,(SQUserPointer*)&methodptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 9 | M method = *methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 10 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 11 | (self->*method)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 12 | |
jhnwkmn | 0:a9a5c12f2d30 | 13 | return 0; |
jhnwkmn | 0:a9a5c12f2d30 | 14 | } |
jhnwkmn | 0:a9a5c12f2d30 | 15 | |
jhnwkmn | 0:a9a5c12f2d30 | 16 | template<class T,$class > |
jhnwkmn | 0:a9a5c12f2d30 | 17 | SQInteger _sqbind_sqmethod_$countc(HSQUIRRELVM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 18 | |
jhnwkmn | 0:a9a5c12f2d30 | 19 | T* self = &SqBind<T>::get(v, 1 ); |
jhnwkmn | 0:a9a5c12f2d30 | 20 | typedef void (T::*M)($paramnames) const; |
jhnwkmn | 0:a9a5c12f2d30 | 21 | M*methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 22 | sq_getuserdata(v,-1,(SQUserPointer*)&methodptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 23 | M method = *methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 24 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 25 | (self->*method)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 26 | |
jhnwkmn | 0:a9a5c12f2d30 | 27 | return 0; |
jhnwkmn | 0:a9a5c12f2d30 | 28 | } |
jhnwkmn | 0:a9a5c12f2d30 | 29 | |
jhnwkmn | 0:a9a5c12f2d30 | 30 | template<class T,$class, class R> |
jhnwkmn | 0:a9a5c12f2d30 | 31 | SQInteger _sqbind_sqmethod_$countr(HSQUIRRELVM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 32 | |
jhnwkmn | 0:a9a5c12f2d30 | 33 | T* self = &SqBind<T>::get(v, 1 ); |
jhnwkmn | 0:a9a5c12f2d30 | 34 | typedef R (T::*M)($paramnames); |
jhnwkmn | 0:a9a5c12f2d30 | 35 | M*methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 36 | sq_getuserdata(v,-1,(SQUserPointer*)&methodptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 37 | M method = *methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 38 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 39 | R r = (self->*method)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 40 | _SQBC( R )::push(v, r ); |
jhnwkmn | 0:a9a5c12f2d30 | 41 | return 1; |
jhnwkmn | 0:a9a5c12f2d30 | 42 | } |
jhnwkmn | 0:a9a5c12f2d30 | 43 | |
jhnwkmn | 0:a9a5c12f2d30 | 44 | template<class T,$class, class R> |
jhnwkmn | 0:a9a5c12f2d30 | 45 | SQInteger _sqbind_sqmethod_$countrc(HSQUIRRELVM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 46 | |
jhnwkmn | 0:a9a5c12f2d30 | 47 | const T* self = &SqBind<T>::get(v, 1 ); |
jhnwkmn | 0:a9a5c12f2d30 | 48 | typedef R (T::*M)($paramnames) const; |
jhnwkmn | 0:a9a5c12f2d30 | 49 | M*methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 50 | sq_getuserdata(v,-1,(SQUserPointer*)&methodptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 51 | M method = *methodptr; |
jhnwkmn | 0:a9a5c12f2d30 | 52 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 53 | R r = (self->*method)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 54 | _SQBC( R )::push(v, r ); |
jhnwkmn | 0:a9a5c12f2d30 | 55 | return 1; |
jhnwkmn | 0:a9a5c12f2d30 | 56 | } |
jhnwkmn | 0:a9a5c12f2d30 | 57 | |
jhnwkmn | 0:a9a5c12f2d30 | 58 | template<class T,$class> |
jhnwkmn | 0:a9a5c12f2d30 | 59 | void sqbind_method( HSQUIRRELVM v, const SQChar *p_name, void (T::*method)($paramnames) ) { |
jhnwkmn | 0:a9a5c12f2d30 | 60 | |
jhnwkmn | 0:a9a5c12f2d30 | 61 | sq_pushobject(v,SqBind<T>::get_id()); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 62 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 63 | sqbind_push_method_userdata(v,method); |
jhnwkmn | 0:a9a5c12f2d30 | 64 | sq_newclosure(v,_sqbind_sqmethod_$count<T,$paramnames>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 65 | sq_newslot(v,-3,false); |
jhnwkmn | 0:a9a5c12f2d30 | 66 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 67 | |
jhnwkmn | 0:a9a5c12f2d30 | 68 | } |
jhnwkmn | 0:a9a5c12f2d30 | 69 | |
jhnwkmn | 0:a9a5c12f2d30 | 70 | template<class T,$class> |
jhnwkmn | 0:a9a5c12f2d30 | 71 | void sqbind_method( HSQUIRRELVM v, const SQChar *p_name, void (T::*method)($paramnames) const ) { |
jhnwkmn | 0:a9a5c12f2d30 | 72 | |
jhnwkmn | 0:a9a5c12f2d30 | 73 | sq_pushobject(v,SqBind<T>::get_id()); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 74 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 75 | sqbind_push_method_userdata(v,method); |
jhnwkmn | 0:a9a5c12f2d30 | 76 | sq_newclosure(v,_sqbind_sqmethod_$countc<T,$paramnames>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 77 | sq_newslot(v,-3,false); |
jhnwkmn | 0:a9a5c12f2d30 | 78 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 79 | |
jhnwkmn | 0:a9a5c12f2d30 | 80 | } |
jhnwkmn | 0:a9a5c12f2d30 | 81 | |
jhnwkmn | 0:a9a5c12f2d30 | 82 | template<class T,$class ,class R> |
jhnwkmn | 0:a9a5c12f2d30 | 83 | void sqbind_method( HSQUIRRELVM v, const SQChar *p_name, R (T::*method)($paramnames) ) { |
jhnwkmn | 0:a9a5c12f2d30 | 84 | |
jhnwkmn | 0:a9a5c12f2d30 | 85 | sq_pushobject(v,SqBind<T>::get_id()); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 86 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 87 | sqbind_push_method_userdata(v,method); |
jhnwkmn | 0:a9a5c12f2d30 | 88 | sq_newclosure(v,_sqbind_sqmethod_$countr<T,$paramnames,R>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 89 | sq_newslot(v,-3,false); |
jhnwkmn | 0:a9a5c12f2d30 | 90 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 91 | |
jhnwkmn | 0:a9a5c12f2d30 | 92 | } |
jhnwkmn | 0:a9a5c12f2d30 | 93 | |
jhnwkmn | 0:a9a5c12f2d30 | 94 | template<class T,$class,class R> |
jhnwkmn | 0:a9a5c12f2d30 | 95 | void sqbind_method( HSQUIRRELVM v, const SQChar *p_name, R (T::*method)($paramnames) const ) { |
jhnwkmn | 0:a9a5c12f2d30 | 96 | |
jhnwkmn | 0:a9a5c12f2d30 | 97 | sq_pushobject(v,SqBind<T>::get_id()); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 98 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 99 | sqbind_push_method_userdata(v,method); |
jhnwkmn | 0:a9a5c12f2d30 | 100 | sq_newclosure(v,_sqbind_sqmethod_$countrc<T,$paramnames,R>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 101 | sq_newslot(v,-3,false); |
jhnwkmn | 0:a9a5c12f2d30 | 102 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 103 | |
jhnwkmn | 0:a9a5c12f2d30 | 104 | } |
jhnwkmn | 0:a9a5c12f2d30 | 105 | |
jhnwkmn | 0:a9a5c12f2d30 | 106 | // STATIC METHODS / FUNCTIONS |
jhnwkmn | 0:a9a5c12f2d30 | 107 | |
jhnwkmn | 0:a9a5c12f2d30 | 108 | // using vm as template parameter.... |
jhnwkmn | 0:a9a5c12f2d30 | 109 | // otherwise overload won't work |
jhnwkmn | 0:a9a5c12f2d30 | 110 | |
jhnwkmn | 0:a9a5c12f2d30 | 111 | template<class VM,$class> |
jhnwkmn | 0:a9a5c12f2d30 | 112 | SQInteger _sqbind_sqfunction_$count(VM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 113 | |
jhnwkmn | 0:a9a5c12f2d30 | 114 | typedef void (*F)($paramnames); |
jhnwkmn | 0:a9a5c12f2d30 | 115 | F*functionptr; |
jhnwkmn | 0:a9a5c12f2d30 | 116 | sq_getuserdata(v,-1,(SQUserPointer*)&functionptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 117 | F function = *functionptr; |
jhnwkmn | 0:a9a5c12f2d30 | 118 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 119 | (function)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 120 | |
jhnwkmn | 0:a9a5c12f2d30 | 121 | return 0; |
jhnwkmn | 0:a9a5c12f2d30 | 122 | } |
jhnwkmn | 0:a9a5c12f2d30 | 123 | |
jhnwkmn | 0:a9a5c12f2d30 | 124 | |
jhnwkmn | 0:a9a5c12f2d30 | 125 | |
jhnwkmn | 0:a9a5c12f2d30 | 126 | template<class VM,$class, class R> |
jhnwkmn | 0:a9a5c12f2d30 | 127 | SQInteger _sqbind_sqfunction_$countr(VM v) { |
jhnwkmn | 0:a9a5c12f2d30 | 128 | |
jhnwkmn | 0:a9a5c12f2d30 | 129 | typedef R (*F)($paramnames); |
jhnwkmn | 0:a9a5c12f2d30 | 130 | F*functionptr; |
jhnwkmn | 0:a9a5c12f2d30 | 131 | sq_getuserdata(v,-1,(SQUserPointer*)&functionptr,NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 132 | F function = *functionptr; |
jhnwkmn | 0:a9a5c12f2d30 | 133 | $params |
jhnwkmn | 0:a9a5c12f2d30 | 134 | R r = (function)($arguments); |
jhnwkmn | 0:a9a5c12f2d30 | 135 | _SQBC( R )::push(v, r ); |
jhnwkmn | 0:a9a5c12f2d30 | 136 | return 1; |
jhnwkmn | 0:a9a5c12f2d30 | 137 | } |
jhnwkmn | 0:a9a5c12f2d30 | 138 | |
jhnwkmn | 0:a9a5c12f2d30 | 139 | //call for functions |
jhnwkmn | 0:a9a5c12f2d30 | 140 | template<class VM,$class> |
jhnwkmn | 0:a9a5c12f2d30 | 141 | void sqbind_function( VM v, const SQChar *p_name, void (*function)($paramnames), const HSQOBJECT *p_class_id=NULL ) { |
jhnwkmn | 0:a9a5c12f2d30 | 142 | |
jhnwkmn | 0:a9a5c12f2d30 | 143 | if (p_class_id) |
jhnwkmn | 0:a9a5c12f2d30 | 144 | sq_pushobject(v,*p_class_id); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 145 | else |
jhnwkmn | 0:a9a5c12f2d30 | 146 | sq_pushroottable(v); |
jhnwkmn | 0:a9a5c12f2d30 | 147 | |
jhnwkmn | 0:a9a5c12f2d30 | 148 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 149 | sqbind_push_method_userdata(v,function); |
jhnwkmn | 0:a9a5c12f2d30 | 150 | sq_newclosure(v,_sqbind_sqfunction_$count<VM,$paramnames>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 151 | sq_newslot(v,-3,p_class_id!=NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 152 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 153 | |
jhnwkmn | 0:a9a5c12f2d30 | 154 | } |
jhnwkmn | 0:a9a5c12f2d30 | 155 | |
jhnwkmn | 0:a9a5c12f2d30 | 156 | |
jhnwkmn | 0:a9a5c12f2d30 | 157 | template<class VM, $class,class R> |
jhnwkmn | 0:a9a5c12f2d30 | 158 | void sqbind_function( VM v, const SQChar *p_name, R (*function)($paramnames), const HSQOBJECT *p_class_id=NULL ) { |
jhnwkmn | 0:a9a5c12f2d30 | 159 | |
jhnwkmn | 0:a9a5c12f2d30 | 160 | if (p_class_id) |
jhnwkmn | 0:a9a5c12f2d30 | 161 | sq_pushobject(v,*p_class_id); // push class |
jhnwkmn | 0:a9a5c12f2d30 | 162 | else |
jhnwkmn | 0:a9a5c12f2d30 | 163 | sq_pushroottable(v); |
jhnwkmn | 0:a9a5c12f2d30 | 164 | sq_pushstring(v,p_name,-1); |
jhnwkmn | 0:a9a5c12f2d30 | 165 | sqbind_push_method_userdata(v,function); |
jhnwkmn | 0:a9a5c12f2d30 | 166 | sq_newclosure(v,_sqbind_sqfunction_$countr<VM,$paramnames,R>,1); |
jhnwkmn | 0:a9a5c12f2d30 | 167 | sq_newslot(v,-3,p_class_id!=NULL); |
jhnwkmn | 0:a9a5c12f2d30 | 168 | sq_pop(v,1); // pop class |
jhnwkmn | 0:a9a5c12f2d30 | 169 | |
jhnwkmn | 0:a9a5c12f2d30 | 170 | } |
jhnwkmn | 0:a9a5c12f2d30 | 171 |