The Squirrel interpreter. See http://www.squirrel-lang.org/

Dependents:   Squirrel

Committer:
jhnwkmn
Date:
Tue Dec 16 10:20:34 2014 +0000
Revision:
0:97a4f8cc534c
Initial import of Squirrel.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:97a4f8cc534c 1 /*
jhnwkmn 0:97a4f8cc534c 2 see copyright notice in squirrel.h
jhnwkmn 0:97a4f8cc534c 3 */
jhnwkmn 0:97a4f8cc534c 4 #include "sqpcheader.h"
jhnwkmn 0:97a4f8cc534c 5 #include "sqvm.h"
jhnwkmn 0:97a4f8cc534c 6 #include "sqstring.h"
jhnwkmn 0:97a4f8cc534c 7 #include "sqtable.h"
jhnwkmn 0:97a4f8cc534c 8 #include "sqarray.h"
jhnwkmn 0:97a4f8cc534c 9 #include "sqfuncproto.h"
jhnwkmn 0:97a4f8cc534c 10 #include "sqclosure.h"
jhnwkmn 0:97a4f8cc534c 11 #include "sqclass.h"
jhnwkmn 0:97a4f8cc534c 12 #include <stdlib.h>
jhnwkmn 0:97a4f8cc534c 13 #include <stdarg.h>
jhnwkmn 0:97a4f8cc534c 14 #include <ctype.h>
jhnwkmn 0:97a4f8cc534c 15
jhnwkmn 0:97a4f8cc534c 16 bool str2num(const SQChar *s,SQObjectPtr &res)
jhnwkmn 0:97a4f8cc534c 17 {
jhnwkmn 0:97a4f8cc534c 18 SQChar *end;
jhnwkmn 0:97a4f8cc534c 19 const SQChar *e = s;
jhnwkmn 0:97a4f8cc534c 20 SQBool isfloat = SQFalse;
jhnwkmn 0:97a4f8cc534c 21 SQChar c;
jhnwkmn 0:97a4f8cc534c 22 while((c = *e) != _SC('\0'))
jhnwkmn 0:97a4f8cc534c 23 {
jhnwkmn 0:97a4f8cc534c 24 if(c == _SC('.') || c == _SC('E')|| c == _SC('e')) { //e and E is for scientific notation
jhnwkmn 0:97a4f8cc534c 25 isfloat = SQTrue;
jhnwkmn 0:97a4f8cc534c 26 break;
jhnwkmn 0:97a4f8cc534c 27 }
jhnwkmn 0:97a4f8cc534c 28 e++;
jhnwkmn 0:97a4f8cc534c 29 }
jhnwkmn 0:97a4f8cc534c 30 if(isfloat){
jhnwkmn 0:97a4f8cc534c 31 SQFloat r = SQFloat(scstrtod(s,&end));
jhnwkmn 0:97a4f8cc534c 32 if(s == end) return false;
jhnwkmn 0:97a4f8cc534c 33 res = r;
jhnwkmn 0:97a4f8cc534c 34 }
jhnwkmn 0:97a4f8cc534c 35 else{
jhnwkmn 0:97a4f8cc534c 36 SQInteger r = SQInteger(scstrtol(s,&end,10));
jhnwkmn 0:97a4f8cc534c 37 if(s == end) return false;
jhnwkmn 0:97a4f8cc534c 38 res = r;
jhnwkmn 0:97a4f8cc534c 39 }
jhnwkmn 0:97a4f8cc534c 40 return true;
jhnwkmn 0:97a4f8cc534c 41 }
jhnwkmn 0:97a4f8cc534c 42
jhnwkmn 0:97a4f8cc534c 43 static SQInteger base_dummy(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 44 {
jhnwkmn 0:97a4f8cc534c 45 return 0;
jhnwkmn 0:97a4f8cc534c 46 }
jhnwkmn 0:97a4f8cc534c 47
jhnwkmn 0:97a4f8cc534c 48 #ifndef NO_GARBAGE_COLLECTOR
jhnwkmn 0:97a4f8cc534c 49 static SQInteger base_collectgarbage(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 50 {
jhnwkmn 0:97a4f8cc534c 51 sq_pushinteger(v, sq_collectgarbage(v));
jhnwkmn 0:97a4f8cc534c 52 return 1;
jhnwkmn 0:97a4f8cc534c 53 }
jhnwkmn 0:97a4f8cc534c 54 static SQInteger base_resurectureachable(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 55 {
jhnwkmn 0:97a4f8cc534c 56 sq_resurrectunreachable(v);
jhnwkmn 0:97a4f8cc534c 57 return 1;
jhnwkmn 0:97a4f8cc534c 58 }
jhnwkmn 0:97a4f8cc534c 59 #endif
jhnwkmn 0:97a4f8cc534c 60
jhnwkmn 0:97a4f8cc534c 61 static SQInteger base_getroottable(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 62 {
jhnwkmn 0:97a4f8cc534c 63 v->Push(v->_roottable);
jhnwkmn 0:97a4f8cc534c 64 return 1;
jhnwkmn 0:97a4f8cc534c 65 }
jhnwkmn 0:97a4f8cc534c 66
jhnwkmn 0:97a4f8cc534c 67 static SQInteger base_getconsttable(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 68 {
jhnwkmn 0:97a4f8cc534c 69 v->Push(_ss(v)->_consts);
jhnwkmn 0:97a4f8cc534c 70 return 1;
jhnwkmn 0:97a4f8cc534c 71 }
jhnwkmn 0:97a4f8cc534c 72
jhnwkmn 0:97a4f8cc534c 73
jhnwkmn 0:97a4f8cc534c 74 static SQInteger base_setroottable(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 75 {
jhnwkmn 0:97a4f8cc534c 76 SQObjectPtr o = v->_roottable;
jhnwkmn 0:97a4f8cc534c 77 if(SQ_FAILED(sq_setroottable(v))) return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 78 v->Push(o);
jhnwkmn 0:97a4f8cc534c 79 return 1;
jhnwkmn 0:97a4f8cc534c 80 }
jhnwkmn 0:97a4f8cc534c 81
jhnwkmn 0:97a4f8cc534c 82 static SQInteger base_setconsttable(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 83 {
jhnwkmn 0:97a4f8cc534c 84 SQObjectPtr o = _ss(v)->_consts;
jhnwkmn 0:97a4f8cc534c 85 if(SQ_FAILED(sq_setconsttable(v))) return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 86 v->Push(o);
jhnwkmn 0:97a4f8cc534c 87 return 1;
jhnwkmn 0:97a4f8cc534c 88 }
jhnwkmn 0:97a4f8cc534c 89
jhnwkmn 0:97a4f8cc534c 90 static SQInteger base_seterrorhandler(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 91 {
jhnwkmn 0:97a4f8cc534c 92 sq_seterrorhandler(v);
jhnwkmn 0:97a4f8cc534c 93 return 0;
jhnwkmn 0:97a4f8cc534c 94 }
jhnwkmn 0:97a4f8cc534c 95
jhnwkmn 0:97a4f8cc534c 96 static SQInteger base_setdebughook(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 97 {
jhnwkmn 0:97a4f8cc534c 98 sq_setdebughook(v);
jhnwkmn 0:97a4f8cc534c 99 return 0;
jhnwkmn 0:97a4f8cc534c 100 }
jhnwkmn 0:97a4f8cc534c 101
jhnwkmn 0:97a4f8cc534c 102 static SQInteger base_enabledebuginfo(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 103 {
jhnwkmn 0:97a4f8cc534c 104 SQObjectPtr &o=stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 105
jhnwkmn 0:97a4f8cc534c 106 sq_enabledebuginfo(v,SQVM::IsFalse(o)?SQFalse:SQTrue);
jhnwkmn 0:97a4f8cc534c 107 return 0;
jhnwkmn 0:97a4f8cc534c 108 }
jhnwkmn 0:97a4f8cc534c 109
jhnwkmn 0:97a4f8cc534c 110 static SQInteger __getcallstackinfos(HSQUIRRELVM v,SQInteger level)
jhnwkmn 0:97a4f8cc534c 111 {
jhnwkmn 0:97a4f8cc534c 112 SQStackInfos si;
jhnwkmn 0:97a4f8cc534c 113 SQInteger seq = 0;
jhnwkmn 0:97a4f8cc534c 114 const SQChar *name = NULL;
jhnwkmn 0:97a4f8cc534c 115
jhnwkmn 0:97a4f8cc534c 116 if (SQ_SUCCEEDED(sq_stackinfos(v, level, &si)))
jhnwkmn 0:97a4f8cc534c 117 {
jhnwkmn 0:97a4f8cc534c 118 const SQChar *fn = _SC("unknown");
jhnwkmn 0:97a4f8cc534c 119 const SQChar *src = _SC("unknown");
jhnwkmn 0:97a4f8cc534c 120 if(si.funcname)fn = si.funcname;
jhnwkmn 0:97a4f8cc534c 121 if(si.source)src = si.source;
jhnwkmn 0:97a4f8cc534c 122 sq_newtable(v);
jhnwkmn 0:97a4f8cc534c 123 sq_pushstring(v, _SC("func"), -1);
jhnwkmn 0:97a4f8cc534c 124 sq_pushstring(v, fn, -1);
jhnwkmn 0:97a4f8cc534c 125 sq_newslot(v, -3, SQFalse);
jhnwkmn 0:97a4f8cc534c 126 sq_pushstring(v, _SC("src"), -1);
jhnwkmn 0:97a4f8cc534c 127 sq_pushstring(v, src, -1);
jhnwkmn 0:97a4f8cc534c 128 sq_newslot(v, -3, SQFalse);
jhnwkmn 0:97a4f8cc534c 129 sq_pushstring(v, _SC("line"), -1);
jhnwkmn 0:97a4f8cc534c 130 sq_pushinteger(v, si.line);
jhnwkmn 0:97a4f8cc534c 131 sq_newslot(v, -3, SQFalse);
jhnwkmn 0:97a4f8cc534c 132 sq_pushstring(v, _SC("locals"), -1);
jhnwkmn 0:97a4f8cc534c 133 sq_newtable(v);
jhnwkmn 0:97a4f8cc534c 134 seq=0;
jhnwkmn 0:97a4f8cc534c 135 while ((name = sq_getlocal(v, level, seq))) {
jhnwkmn 0:97a4f8cc534c 136 sq_pushstring(v, name, -1);
jhnwkmn 0:97a4f8cc534c 137 sq_push(v, -2);
jhnwkmn 0:97a4f8cc534c 138 sq_newslot(v, -4, SQFalse);
jhnwkmn 0:97a4f8cc534c 139 sq_pop(v, 1);
jhnwkmn 0:97a4f8cc534c 140 seq++;
jhnwkmn 0:97a4f8cc534c 141 }
jhnwkmn 0:97a4f8cc534c 142 sq_newslot(v, -3, SQFalse);
jhnwkmn 0:97a4f8cc534c 143 return 1;
jhnwkmn 0:97a4f8cc534c 144 }
jhnwkmn 0:97a4f8cc534c 145
jhnwkmn 0:97a4f8cc534c 146 return 0;
jhnwkmn 0:97a4f8cc534c 147 }
jhnwkmn 0:97a4f8cc534c 148 static SQInteger base_getstackinfos(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 149 {
jhnwkmn 0:97a4f8cc534c 150 SQInteger level;
jhnwkmn 0:97a4f8cc534c 151 sq_getinteger(v, -1, &level);
jhnwkmn 0:97a4f8cc534c 152 return __getcallstackinfos(v,level);
jhnwkmn 0:97a4f8cc534c 153 }
jhnwkmn 0:97a4f8cc534c 154
jhnwkmn 0:97a4f8cc534c 155 static SQInteger base_assert(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 156 {
jhnwkmn 0:97a4f8cc534c 157 if(SQVM::IsFalse(stack_get(v,2))){
jhnwkmn 0:97a4f8cc534c 158 return sq_throwerror(v,_SC("assertion failed"));
jhnwkmn 0:97a4f8cc534c 159 }
jhnwkmn 0:97a4f8cc534c 160 return 0;
jhnwkmn 0:97a4f8cc534c 161 }
jhnwkmn 0:97a4f8cc534c 162
jhnwkmn 0:97a4f8cc534c 163 static SQInteger get_slice_params(HSQUIRRELVM v,SQInteger &sidx,SQInteger &eidx,SQObjectPtr &o)
jhnwkmn 0:97a4f8cc534c 164 {
jhnwkmn 0:97a4f8cc534c 165 SQInteger top = sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 166 sidx=0;
jhnwkmn 0:97a4f8cc534c 167 eidx=0;
jhnwkmn 0:97a4f8cc534c 168 o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 169 SQObjectPtr &start=stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 170 if(type(start)!=OT_NULL && sq_isnumeric(start)){
jhnwkmn 0:97a4f8cc534c 171 sidx=tointeger(start);
jhnwkmn 0:97a4f8cc534c 172 }
jhnwkmn 0:97a4f8cc534c 173 if(top>2){
jhnwkmn 0:97a4f8cc534c 174 SQObjectPtr &end=stack_get(v,3);
jhnwkmn 0:97a4f8cc534c 175 if(sq_isnumeric(end)){
jhnwkmn 0:97a4f8cc534c 176 eidx=tointeger(end);
jhnwkmn 0:97a4f8cc534c 177 }
jhnwkmn 0:97a4f8cc534c 178 }
jhnwkmn 0:97a4f8cc534c 179 else {
jhnwkmn 0:97a4f8cc534c 180 eidx = sq_getsize(v,1);
jhnwkmn 0:97a4f8cc534c 181 }
jhnwkmn 0:97a4f8cc534c 182 return 1;
jhnwkmn 0:97a4f8cc534c 183 }
jhnwkmn 0:97a4f8cc534c 184
jhnwkmn 0:97a4f8cc534c 185 static SQInteger base_print(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 186 {
jhnwkmn 0:97a4f8cc534c 187 const SQChar *str;
jhnwkmn 0:97a4f8cc534c 188 sq_tostring(v,2);
jhnwkmn 0:97a4f8cc534c 189 sq_getstring(v,-1,&str);
jhnwkmn 0:97a4f8cc534c 190 if(_ss(v)->_printfunc) _ss(v)->_printfunc(v,_SC("%s"),str);
jhnwkmn 0:97a4f8cc534c 191 return 0;
jhnwkmn 0:97a4f8cc534c 192 }
jhnwkmn 0:97a4f8cc534c 193
jhnwkmn 0:97a4f8cc534c 194 static SQInteger base_error(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 195 {
jhnwkmn 0:97a4f8cc534c 196 const SQChar *str;
jhnwkmn 0:97a4f8cc534c 197 sq_tostring(v,2);
jhnwkmn 0:97a4f8cc534c 198 sq_getstring(v,-1,&str);
jhnwkmn 0:97a4f8cc534c 199 if(_ss(v)->_errorfunc) _ss(v)->_errorfunc(v,_SC("%s"),str);
jhnwkmn 0:97a4f8cc534c 200 return 0;
jhnwkmn 0:97a4f8cc534c 201 }
jhnwkmn 0:97a4f8cc534c 202
jhnwkmn 0:97a4f8cc534c 203 static SQInteger base_compilestring(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 204 {
jhnwkmn 0:97a4f8cc534c 205 SQInteger nargs=sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 206 const SQChar *src=NULL,*name=_SC("unnamedbuffer");
jhnwkmn 0:97a4f8cc534c 207 SQInteger size;
jhnwkmn 0:97a4f8cc534c 208 sq_getstring(v,2,&src);
jhnwkmn 0:97a4f8cc534c 209 size=sq_getsize(v,2);
jhnwkmn 0:97a4f8cc534c 210 if(nargs>2){
jhnwkmn 0:97a4f8cc534c 211 sq_getstring(v,3,&name);
jhnwkmn 0:97a4f8cc534c 212 }
jhnwkmn 0:97a4f8cc534c 213 if(SQ_SUCCEEDED(sq_compilebuffer(v,src,size,name,SQFalse)))
jhnwkmn 0:97a4f8cc534c 214 return 1;
jhnwkmn 0:97a4f8cc534c 215 else
jhnwkmn 0:97a4f8cc534c 216 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 217 }
jhnwkmn 0:97a4f8cc534c 218
jhnwkmn 0:97a4f8cc534c 219 static SQInteger base_newthread(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 220 {
jhnwkmn 0:97a4f8cc534c 221 SQObjectPtr &func = stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 222 SQInteger stksize = (_closure(func)->_function->_stacksize << 1) +2;
jhnwkmn 0:97a4f8cc534c 223 HSQUIRRELVM newv = sq_newthread(v, (stksize < MIN_STACK_OVERHEAD + 2)? MIN_STACK_OVERHEAD + 2 : stksize);
jhnwkmn 0:97a4f8cc534c 224 sq_move(newv,v,-2);
jhnwkmn 0:97a4f8cc534c 225 return 1;
jhnwkmn 0:97a4f8cc534c 226 }
jhnwkmn 0:97a4f8cc534c 227
jhnwkmn 0:97a4f8cc534c 228 static SQInteger base_suspend(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 229 {
jhnwkmn 0:97a4f8cc534c 230 return sq_suspendvm(v);
jhnwkmn 0:97a4f8cc534c 231 }
jhnwkmn 0:97a4f8cc534c 232
jhnwkmn 0:97a4f8cc534c 233 static SQInteger base_array(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 234 {
jhnwkmn 0:97a4f8cc534c 235 SQArray *a;
jhnwkmn 0:97a4f8cc534c 236 SQObject &size = stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 237 if(sq_gettop(v) > 2) {
jhnwkmn 0:97a4f8cc534c 238 a = SQArray::Create(_ss(v),0);
jhnwkmn 0:97a4f8cc534c 239 a->Resize(tointeger(size),stack_get(v,3));
jhnwkmn 0:97a4f8cc534c 240 }
jhnwkmn 0:97a4f8cc534c 241 else {
jhnwkmn 0:97a4f8cc534c 242 a = SQArray::Create(_ss(v),tointeger(size));
jhnwkmn 0:97a4f8cc534c 243 }
jhnwkmn 0:97a4f8cc534c 244 v->Push(a);
jhnwkmn 0:97a4f8cc534c 245 return 1;
jhnwkmn 0:97a4f8cc534c 246 }
jhnwkmn 0:97a4f8cc534c 247
jhnwkmn 0:97a4f8cc534c 248 static SQInteger base_type(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 249 {
jhnwkmn 0:97a4f8cc534c 250 SQObjectPtr &o = stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 251 v->Push(SQString::Create(_ss(v),GetTypeName(o),-1));
jhnwkmn 0:97a4f8cc534c 252 return 1;
jhnwkmn 0:97a4f8cc534c 253 }
jhnwkmn 0:97a4f8cc534c 254
jhnwkmn 0:97a4f8cc534c 255 static SQInteger base_callee(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 256 {
jhnwkmn 0:97a4f8cc534c 257 if(v->_callsstacksize > 1)
jhnwkmn 0:97a4f8cc534c 258 {
jhnwkmn 0:97a4f8cc534c 259 v->Push(v->_callsstack[v->_callsstacksize - 2]._closure);
jhnwkmn 0:97a4f8cc534c 260 return 1;
jhnwkmn 0:97a4f8cc534c 261 }
jhnwkmn 0:97a4f8cc534c 262 return sq_throwerror(v,_SC("no closure in the calls stack"));
jhnwkmn 0:97a4f8cc534c 263 }
jhnwkmn 0:97a4f8cc534c 264
jhnwkmn 0:97a4f8cc534c 265 static SQRegFunction base_funcs[]={
jhnwkmn 0:97a4f8cc534c 266 //generic
jhnwkmn 0:97a4f8cc534c 267 {_SC("seterrorhandler"),base_seterrorhandler,2, NULL},
jhnwkmn 0:97a4f8cc534c 268 {_SC("setdebughook"),base_setdebughook,2, NULL},
jhnwkmn 0:97a4f8cc534c 269 {_SC("enabledebuginfo"),base_enabledebuginfo,2, NULL},
jhnwkmn 0:97a4f8cc534c 270 {_SC("getstackinfos"),base_getstackinfos,2, _SC(".n")},
jhnwkmn 0:97a4f8cc534c 271 {_SC("getroottable"),base_getroottable,1, NULL},
jhnwkmn 0:97a4f8cc534c 272 {_SC("setroottable"),base_setroottable,2, NULL},
jhnwkmn 0:97a4f8cc534c 273 {_SC("getconsttable"),base_getconsttable,1, NULL},
jhnwkmn 0:97a4f8cc534c 274 {_SC("setconsttable"),base_setconsttable,2, NULL},
jhnwkmn 0:97a4f8cc534c 275 {_SC("assert"),base_assert,2, NULL},
jhnwkmn 0:97a4f8cc534c 276 {_SC("print"),base_print,2, NULL},
jhnwkmn 0:97a4f8cc534c 277 {_SC("error"),base_error,2, NULL},
jhnwkmn 0:97a4f8cc534c 278 {_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
jhnwkmn 0:97a4f8cc534c 279 {_SC("newthread"),base_newthread,2, _SC(".c")},
jhnwkmn 0:97a4f8cc534c 280 {_SC("suspend"),base_suspend,-1, NULL},
jhnwkmn 0:97a4f8cc534c 281 {_SC("array"),base_array,-2, _SC(".n")},
jhnwkmn 0:97a4f8cc534c 282 {_SC("type"),base_type,2, NULL},
jhnwkmn 0:97a4f8cc534c 283 {_SC("callee"),base_callee,0,NULL},
jhnwkmn 0:97a4f8cc534c 284 {_SC("dummy"),base_dummy,0,NULL},
jhnwkmn 0:97a4f8cc534c 285 #ifndef NO_GARBAGE_COLLECTOR
jhnwkmn 0:97a4f8cc534c 286 {_SC("collectgarbage"),base_collectgarbage,0, NULL},
jhnwkmn 0:97a4f8cc534c 287 {_SC("resurrectunreachable"),base_resurectureachable,0, NULL},
jhnwkmn 0:97a4f8cc534c 288 #endif
jhnwkmn 0:97a4f8cc534c 289 {0,0}
jhnwkmn 0:97a4f8cc534c 290 };
jhnwkmn 0:97a4f8cc534c 291
jhnwkmn 0:97a4f8cc534c 292 void sq_base_register(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 293 {
jhnwkmn 0:97a4f8cc534c 294 SQInteger i=0;
jhnwkmn 0:97a4f8cc534c 295 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 296 while(base_funcs[i].name!=0) {
jhnwkmn 0:97a4f8cc534c 297 sq_pushstring(v,base_funcs[i].name,-1);
jhnwkmn 0:97a4f8cc534c 298 sq_newclosure(v,base_funcs[i].f,0);
jhnwkmn 0:97a4f8cc534c 299 sq_setnativeclosurename(v,-1,base_funcs[i].name);
jhnwkmn 0:97a4f8cc534c 300 sq_setparamscheck(v,base_funcs[i].nparamscheck,base_funcs[i].typemask);
jhnwkmn 0:97a4f8cc534c 301 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 302 i++;
jhnwkmn 0:97a4f8cc534c 303 }
jhnwkmn 0:97a4f8cc534c 304
jhnwkmn 0:97a4f8cc534c 305 sq_pushstring(v,_SC("_versionnumber_"),-1);
jhnwkmn 0:97a4f8cc534c 306 sq_pushinteger(v,SQUIRREL_VERSION_NUMBER);
jhnwkmn 0:97a4f8cc534c 307 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 308 sq_pushstring(v,_SC("_version_"),-1);
jhnwkmn 0:97a4f8cc534c 309 sq_pushstring(v,SQUIRREL_VERSION,-1);
jhnwkmn 0:97a4f8cc534c 310 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 311 sq_pushstring(v,_SC("_charsize_"),-1);
jhnwkmn 0:97a4f8cc534c 312 sq_pushinteger(v,sizeof(SQChar));
jhnwkmn 0:97a4f8cc534c 313 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 314 sq_pushstring(v,_SC("_intsize_"),-1);
jhnwkmn 0:97a4f8cc534c 315 sq_pushinteger(v,sizeof(SQInteger));
jhnwkmn 0:97a4f8cc534c 316 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 317 sq_pushstring(v,_SC("_floatsize_"),-1);
jhnwkmn 0:97a4f8cc534c 318 sq_pushinteger(v,sizeof(SQFloat));
jhnwkmn 0:97a4f8cc534c 319 sq_newslot(v,-3, SQFalse);
jhnwkmn 0:97a4f8cc534c 320 sq_pop(v,1);
jhnwkmn 0:97a4f8cc534c 321 }
jhnwkmn 0:97a4f8cc534c 322
jhnwkmn 0:97a4f8cc534c 323 static SQInteger default_delegate_len(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 324 {
jhnwkmn 0:97a4f8cc534c 325 v->Push(SQInteger(sq_getsize(v,1)));
jhnwkmn 0:97a4f8cc534c 326 return 1;
jhnwkmn 0:97a4f8cc534c 327 }
jhnwkmn 0:97a4f8cc534c 328
jhnwkmn 0:97a4f8cc534c 329 static SQInteger default_delegate_tofloat(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 330 {
jhnwkmn 0:97a4f8cc534c 331 SQObjectPtr &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 332 switch(type(o)){
jhnwkmn 0:97a4f8cc534c 333 case OT_STRING:{
jhnwkmn 0:97a4f8cc534c 334 SQObjectPtr res;
jhnwkmn 0:97a4f8cc534c 335 if(str2num(_stringval(o),res)){
jhnwkmn 0:97a4f8cc534c 336 v->Push(SQObjectPtr(tofloat(res)));
jhnwkmn 0:97a4f8cc534c 337 break;
jhnwkmn 0:97a4f8cc534c 338 }}
jhnwkmn 0:97a4f8cc534c 339 return sq_throwerror(v, _SC("cannot convert the string"));
jhnwkmn 0:97a4f8cc534c 340 break;
jhnwkmn 0:97a4f8cc534c 341 case OT_INTEGER:case OT_FLOAT:
jhnwkmn 0:97a4f8cc534c 342 v->Push(SQObjectPtr(tofloat(o)));
jhnwkmn 0:97a4f8cc534c 343 break;
jhnwkmn 0:97a4f8cc534c 344 case OT_BOOL:
jhnwkmn 0:97a4f8cc534c 345 v->Push(SQObjectPtr((SQFloat)(_integer(o)?1:0)));
jhnwkmn 0:97a4f8cc534c 346 break;
jhnwkmn 0:97a4f8cc534c 347 default:
jhnwkmn 0:97a4f8cc534c 348 v->PushNull();
jhnwkmn 0:97a4f8cc534c 349 break;
jhnwkmn 0:97a4f8cc534c 350 }
jhnwkmn 0:97a4f8cc534c 351 return 1;
jhnwkmn 0:97a4f8cc534c 352 }
jhnwkmn 0:97a4f8cc534c 353
jhnwkmn 0:97a4f8cc534c 354 static SQInteger default_delegate_tointeger(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 355 {
jhnwkmn 0:97a4f8cc534c 356 SQObjectPtr &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 357 switch(type(o)){
jhnwkmn 0:97a4f8cc534c 358 case OT_STRING:{
jhnwkmn 0:97a4f8cc534c 359 SQObjectPtr res;
jhnwkmn 0:97a4f8cc534c 360 if(str2num(_stringval(o),res)){
jhnwkmn 0:97a4f8cc534c 361 v->Push(SQObjectPtr(tointeger(res)));
jhnwkmn 0:97a4f8cc534c 362 break;
jhnwkmn 0:97a4f8cc534c 363 }}
jhnwkmn 0:97a4f8cc534c 364 return sq_throwerror(v, _SC("cannot convert the string"));
jhnwkmn 0:97a4f8cc534c 365 break;
jhnwkmn 0:97a4f8cc534c 366 case OT_INTEGER:case OT_FLOAT:
jhnwkmn 0:97a4f8cc534c 367 v->Push(SQObjectPtr(tointeger(o)));
jhnwkmn 0:97a4f8cc534c 368 break;
jhnwkmn 0:97a4f8cc534c 369 case OT_BOOL:
jhnwkmn 0:97a4f8cc534c 370 v->Push(SQObjectPtr(_integer(o)?(SQInteger)1:(SQInteger)0));
jhnwkmn 0:97a4f8cc534c 371 break;
jhnwkmn 0:97a4f8cc534c 372 default:
jhnwkmn 0:97a4f8cc534c 373 v->PushNull();
jhnwkmn 0:97a4f8cc534c 374 break;
jhnwkmn 0:97a4f8cc534c 375 }
jhnwkmn 0:97a4f8cc534c 376 return 1;
jhnwkmn 0:97a4f8cc534c 377 }
jhnwkmn 0:97a4f8cc534c 378
jhnwkmn 0:97a4f8cc534c 379 static SQInteger default_delegate_tostring(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 380 {
jhnwkmn 0:97a4f8cc534c 381 sq_tostring(v,1);
jhnwkmn 0:97a4f8cc534c 382 return 1;
jhnwkmn 0:97a4f8cc534c 383 }
jhnwkmn 0:97a4f8cc534c 384
jhnwkmn 0:97a4f8cc534c 385 static SQInteger obj_delegate_weakref(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 386 {
jhnwkmn 0:97a4f8cc534c 387 sq_weakref(v,1);
jhnwkmn 0:97a4f8cc534c 388 return 1;
jhnwkmn 0:97a4f8cc534c 389 }
jhnwkmn 0:97a4f8cc534c 390
jhnwkmn 0:97a4f8cc534c 391 static SQInteger obj_clear(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 392 {
jhnwkmn 0:97a4f8cc534c 393 return sq_clear(v,-1);
jhnwkmn 0:97a4f8cc534c 394 }
jhnwkmn 0:97a4f8cc534c 395
jhnwkmn 0:97a4f8cc534c 396
jhnwkmn 0:97a4f8cc534c 397 static SQInteger number_delegate_tochar(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 398 {
jhnwkmn 0:97a4f8cc534c 399 SQObject &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 400 SQChar c = (SQChar)tointeger(o);
jhnwkmn 0:97a4f8cc534c 401 v->Push(SQString::Create(_ss(v),(const SQChar *)&c,1));
jhnwkmn 0:97a4f8cc534c 402 return 1;
jhnwkmn 0:97a4f8cc534c 403 }
jhnwkmn 0:97a4f8cc534c 404
jhnwkmn 0:97a4f8cc534c 405
jhnwkmn 0:97a4f8cc534c 406
jhnwkmn 0:97a4f8cc534c 407 /////////////////////////////////////////////////////////////////
jhnwkmn 0:97a4f8cc534c 408 //TABLE DEFAULT DELEGATE
jhnwkmn 0:97a4f8cc534c 409
jhnwkmn 0:97a4f8cc534c 410 static SQInteger table_rawdelete(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 411 {
jhnwkmn 0:97a4f8cc534c 412 if(SQ_FAILED(sq_rawdeleteslot(v,1,SQTrue)))
jhnwkmn 0:97a4f8cc534c 413 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 414 return 1;
jhnwkmn 0:97a4f8cc534c 415 }
jhnwkmn 0:97a4f8cc534c 416
jhnwkmn 0:97a4f8cc534c 417
jhnwkmn 0:97a4f8cc534c 418 static SQInteger container_rawexists(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 419 {
jhnwkmn 0:97a4f8cc534c 420 if(SQ_SUCCEEDED(sq_rawget(v,-2))) {
jhnwkmn 0:97a4f8cc534c 421 sq_pushbool(v,SQTrue);
jhnwkmn 0:97a4f8cc534c 422 return 1;
jhnwkmn 0:97a4f8cc534c 423 }
jhnwkmn 0:97a4f8cc534c 424 sq_pushbool(v,SQFalse);
jhnwkmn 0:97a4f8cc534c 425 return 1;
jhnwkmn 0:97a4f8cc534c 426 }
jhnwkmn 0:97a4f8cc534c 427
jhnwkmn 0:97a4f8cc534c 428 static SQInteger container_rawset(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 429 {
jhnwkmn 0:97a4f8cc534c 430 return sq_rawset(v,-3);
jhnwkmn 0:97a4f8cc534c 431 }
jhnwkmn 0:97a4f8cc534c 432
jhnwkmn 0:97a4f8cc534c 433
jhnwkmn 0:97a4f8cc534c 434 static SQInteger container_rawget(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 435 {
jhnwkmn 0:97a4f8cc534c 436 return SQ_SUCCEEDED(sq_rawget(v,-2))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 437 }
jhnwkmn 0:97a4f8cc534c 438
jhnwkmn 0:97a4f8cc534c 439 static SQInteger table_setdelegate(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 440 {
jhnwkmn 0:97a4f8cc534c 441 if(SQ_FAILED(sq_setdelegate(v,-2)))
jhnwkmn 0:97a4f8cc534c 442 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 443 sq_push(v,-1); // -1 because sq_setdelegate pops 1
jhnwkmn 0:97a4f8cc534c 444 return 1;
jhnwkmn 0:97a4f8cc534c 445 }
jhnwkmn 0:97a4f8cc534c 446
jhnwkmn 0:97a4f8cc534c 447 static SQInteger table_getdelegate(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 448 {
jhnwkmn 0:97a4f8cc534c 449 return SQ_SUCCEEDED(sq_getdelegate(v,-1))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 450 }
jhnwkmn 0:97a4f8cc534c 451
jhnwkmn 0:97a4f8cc534c 452 SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 453 {_SC("len"),default_delegate_len,1, _SC("t")},
jhnwkmn 0:97a4f8cc534c 454 {_SC("rawget"),container_rawget,2, _SC("t")},
jhnwkmn 0:97a4f8cc534c 455 {_SC("rawset"),container_rawset,3, _SC("t")},
jhnwkmn 0:97a4f8cc534c 456 {_SC("rawdelete"),table_rawdelete,2, _SC("t")},
jhnwkmn 0:97a4f8cc534c 457 {_SC("rawin"),container_rawexists,2, _SC("t")},
jhnwkmn 0:97a4f8cc534c 458 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 459 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 460 {_SC("clear"),obj_clear,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 461 {_SC("setdelegate"),table_setdelegate,2, _SC(".t|o")},
jhnwkmn 0:97a4f8cc534c 462 {_SC("getdelegate"),table_getdelegate,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 463 {0,0}
jhnwkmn 0:97a4f8cc534c 464 };
jhnwkmn 0:97a4f8cc534c 465
jhnwkmn 0:97a4f8cc534c 466 //ARRAY DEFAULT DELEGATE///////////////////////////////////////
jhnwkmn 0:97a4f8cc534c 467
jhnwkmn 0:97a4f8cc534c 468 static SQInteger array_append(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 469 {
jhnwkmn 0:97a4f8cc534c 470 return sq_arrayappend(v,-2);
jhnwkmn 0:97a4f8cc534c 471 }
jhnwkmn 0:97a4f8cc534c 472
jhnwkmn 0:97a4f8cc534c 473 static SQInteger array_extend(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 474 {
jhnwkmn 0:97a4f8cc534c 475 _array(stack_get(v,1))->Extend(_array(stack_get(v,2)));
jhnwkmn 0:97a4f8cc534c 476 return 0;
jhnwkmn 0:97a4f8cc534c 477 }
jhnwkmn 0:97a4f8cc534c 478
jhnwkmn 0:97a4f8cc534c 479 static SQInteger array_reverse(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 480 {
jhnwkmn 0:97a4f8cc534c 481 return sq_arrayreverse(v,-1);
jhnwkmn 0:97a4f8cc534c 482 }
jhnwkmn 0:97a4f8cc534c 483
jhnwkmn 0:97a4f8cc534c 484 static SQInteger array_pop(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 485 {
jhnwkmn 0:97a4f8cc534c 486 return SQ_SUCCEEDED(sq_arraypop(v,1,SQTrue))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 487 }
jhnwkmn 0:97a4f8cc534c 488
jhnwkmn 0:97a4f8cc534c 489 static SQInteger array_top(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 490 {
jhnwkmn 0:97a4f8cc534c 491 SQObject &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 492 if(_array(o)->Size()>0){
jhnwkmn 0:97a4f8cc534c 493 v->Push(_array(o)->Top());
jhnwkmn 0:97a4f8cc534c 494 return 1;
jhnwkmn 0:97a4f8cc534c 495 }
jhnwkmn 0:97a4f8cc534c 496 else return sq_throwerror(v,_SC("top() on a empty array"));
jhnwkmn 0:97a4f8cc534c 497 }
jhnwkmn 0:97a4f8cc534c 498
jhnwkmn 0:97a4f8cc534c 499 static SQInteger array_insert(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 500 {
jhnwkmn 0:97a4f8cc534c 501 SQObject &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 502 SQObject &idx=stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 503 SQObject &val=stack_get(v,3);
jhnwkmn 0:97a4f8cc534c 504 if(!_array(o)->Insert(tointeger(idx),val))
jhnwkmn 0:97a4f8cc534c 505 return sq_throwerror(v,_SC("index out of range"));
jhnwkmn 0:97a4f8cc534c 506 return 0;
jhnwkmn 0:97a4f8cc534c 507 }
jhnwkmn 0:97a4f8cc534c 508
jhnwkmn 0:97a4f8cc534c 509 static SQInteger array_remove(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 510 {
jhnwkmn 0:97a4f8cc534c 511 SQObject &o = stack_get(v, 1);
jhnwkmn 0:97a4f8cc534c 512 SQObject &idx = stack_get(v, 2);
jhnwkmn 0:97a4f8cc534c 513 if(!sq_isnumeric(idx)) return sq_throwerror(v, _SC("wrong type"));
jhnwkmn 0:97a4f8cc534c 514 SQObjectPtr val;
jhnwkmn 0:97a4f8cc534c 515 if(_array(o)->Get(tointeger(idx), val)) {
jhnwkmn 0:97a4f8cc534c 516 _array(o)->Remove(tointeger(idx));
jhnwkmn 0:97a4f8cc534c 517 v->Push(val);
jhnwkmn 0:97a4f8cc534c 518 return 1;
jhnwkmn 0:97a4f8cc534c 519 }
jhnwkmn 0:97a4f8cc534c 520 return sq_throwerror(v, _SC("idx out of range"));
jhnwkmn 0:97a4f8cc534c 521 }
jhnwkmn 0:97a4f8cc534c 522
jhnwkmn 0:97a4f8cc534c 523 static SQInteger array_resize(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 524 {
jhnwkmn 0:97a4f8cc534c 525 SQObject &o = stack_get(v, 1);
jhnwkmn 0:97a4f8cc534c 526 SQObject &nsize = stack_get(v, 2);
jhnwkmn 0:97a4f8cc534c 527 SQObjectPtr fill;
jhnwkmn 0:97a4f8cc534c 528 if(sq_isnumeric(nsize)) {
jhnwkmn 0:97a4f8cc534c 529 if(sq_gettop(v) > 2)
jhnwkmn 0:97a4f8cc534c 530 fill = stack_get(v, 3);
jhnwkmn 0:97a4f8cc534c 531 _array(o)->Resize(tointeger(nsize),fill);
jhnwkmn 0:97a4f8cc534c 532 return 0;
jhnwkmn 0:97a4f8cc534c 533 }
jhnwkmn 0:97a4f8cc534c 534 return sq_throwerror(v, _SC("size must be a number"));
jhnwkmn 0:97a4f8cc534c 535 }
jhnwkmn 0:97a4f8cc534c 536
jhnwkmn 0:97a4f8cc534c 537 static SQInteger __map_array(SQArray *dest,SQArray *src,HSQUIRRELVM v) {
jhnwkmn 0:97a4f8cc534c 538 SQObjectPtr temp;
jhnwkmn 0:97a4f8cc534c 539 SQInteger size = src->Size();
jhnwkmn 0:97a4f8cc534c 540 for(SQInteger n = 0; n < size; n++) {
jhnwkmn 0:97a4f8cc534c 541 src->Get(n,temp);
jhnwkmn 0:97a4f8cc534c 542 v->Push(src);
jhnwkmn 0:97a4f8cc534c 543 v->Push(temp);
jhnwkmn 0:97a4f8cc534c 544 if(SQ_FAILED(sq_call(v,2,SQTrue,SQFalse))) {
jhnwkmn 0:97a4f8cc534c 545 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 546 }
jhnwkmn 0:97a4f8cc534c 547 dest->Set(n,v->GetUp(-1));
jhnwkmn 0:97a4f8cc534c 548 v->Pop();
jhnwkmn 0:97a4f8cc534c 549 }
jhnwkmn 0:97a4f8cc534c 550 return 0;
jhnwkmn 0:97a4f8cc534c 551 }
jhnwkmn 0:97a4f8cc534c 552
jhnwkmn 0:97a4f8cc534c 553 static SQInteger array_map(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 554 {
jhnwkmn 0:97a4f8cc534c 555 SQObject &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 556 SQInteger size = _array(o)->Size();
jhnwkmn 0:97a4f8cc534c 557 SQObjectPtr ret = SQArray::Create(_ss(v),size);
jhnwkmn 0:97a4f8cc534c 558 if(SQ_FAILED(__map_array(_array(ret),_array(o),v)))
jhnwkmn 0:97a4f8cc534c 559 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 560 v->Push(ret);
jhnwkmn 0:97a4f8cc534c 561 return 1;
jhnwkmn 0:97a4f8cc534c 562 }
jhnwkmn 0:97a4f8cc534c 563
jhnwkmn 0:97a4f8cc534c 564 static SQInteger array_apply(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 565 {
jhnwkmn 0:97a4f8cc534c 566 SQObject &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 567 if(SQ_FAILED(__map_array(_array(o),_array(o),v)))
jhnwkmn 0:97a4f8cc534c 568 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 569 return 0;
jhnwkmn 0:97a4f8cc534c 570 }
jhnwkmn 0:97a4f8cc534c 571
jhnwkmn 0:97a4f8cc534c 572 static SQInteger array_reduce(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 573 {
jhnwkmn 0:97a4f8cc534c 574 SQObject &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 575 SQArray *a = _array(o);
jhnwkmn 0:97a4f8cc534c 576 SQInteger size = a->Size();
jhnwkmn 0:97a4f8cc534c 577 if(size == 0) {
jhnwkmn 0:97a4f8cc534c 578 return 0;
jhnwkmn 0:97a4f8cc534c 579 }
jhnwkmn 0:97a4f8cc534c 580 SQObjectPtr res;
jhnwkmn 0:97a4f8cc534c 581 a->Get(0,res);
jhnwkmn 0:97a4f8cc534c 582 if(size > 1) {
jhnwkmn 0:97a4f8cc534c 583 SQObjectPtr other;
jhnwkmn 0:97a4f8cc534c 584 for(SQInteger n = 1; n < size; n++) {
jhnwkmn 0:97a4f8cc534c 585 a->Get(n,other);
jhnwkmn 0:97a4f8cc534c 586 v->Push(o);
jhnwkmn 0:97a4f8cc534c 587 v->Push(res);
jhnwkmn 0:97a4f8cc534c 588 v->Push(other);
jhnwkmn 0:97a4f8cc534c 589 if(SQ_FAILED(sq_call(v,3,SQTrue,SQFalse))) {
jhnwkmn 0:97a4f8cc534c 590 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 591 }
jhnwkmn 0:97a4f8cc534c 592 res = v->GetUp(-1);
jhnwkmn 0:97a4f8cc534c 593 v->Pop();
jhnwkmn 0:97a4f8cc534c 594 }
jhnwkmn 0:97a4f8cc534c 595 }
jhnwkmn 0:97a4f8cc534c 596 v->Push(res);
jhnwkmn 0:97a4f8cc534c 597 return 1;
jhnwkmn 0:97a4f8cc534c 598 }
jhnwkmn 0:97a4f8cc534c 599
jhnwkmn 0:97a4f8cc534c 600 static SQInteger array_filter(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 601 {
jhnwkmn 0:97a4f8cc534c 602 SQObject &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 603 SQArray *a = _array(o);
jhnwkmn 0:97a4f8cc534c 604 SQObjectPtr ret = SQArray::Create(_ss(v),0);
jhnwkmn 0:97a4f8cc534c 605 SQInteger size = a->Size();
jhnwkmn 0:97a4f8cc534c 606 SQObjectPtr val;
jhnwkmn 0:97a4f8cc534c 607 for(SQInteger n = 0; n < size; n++) {
jhnwkmn 0:97a4f8cc534c 608 a->Get(n,val);
jhnwkmn 0:97a4f8cc534c 609 v->Push(o);
jhnwkmn 0:97a4f8cc534c 610 v->Push(n);
jhnwkmn 0:97a4f8cc534c 611 v->Push(val);
jhnwkmn 0:97a4f8cc534c 612 if(SQ_FAILED(sq_call(v,3,SQTrue,SQFalse))) {
jhnwkmn 0:97a4f8cc534c 613 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 614 }
jhnwkmn 0:97a4f8cc534c 615 if(!SQVM::IsFalse(v->GetUp(-1))) {
jhnwkmn 0:97a4f8cc534c 616 _array(ret)->Append(val);
jhnwkmn 0:97a4f8cc534c 617 }
jhnwkmn 0:97a4f8cc534c 618 v->Pop();
jhnwkmn 0:97a4f8cc534c 619 }
jhnwkmn 0:97a4f8cc534c 620 v->Push(ret);
jhnwkmn 0:97a4f8cc534c 621 return 1;
jhnwkmn 0:97a4f8cc534c 622 }
jhnwkmn 0:97a4f8cc534c 623
jhnwkmn 0:97a4f8cc534c 624 static SQInteger array_find(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 625 {
jhnwkmn 0:97a4f8cc534c 626 SQObject &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 627 SQObjectPtr &val = stack_get(v,2);
jhnwkmn 0:97a4f8cc534c 628 SQArray *a = _array(o);
jhnwkmn 0:97a4f8cc534c 629 SQInteger size = a->Size();
jhnwkmn 0:97a4f8cc534c 630 SQObjectPtr temp;
jhnwkmn 0:97a4f8cc534c 631 for(SQInteger n = 0; n < size; n++) {
jhnwkmn 0:97a4f8cc534c 632 bool res = false;
jhnwkmn 0:97a4f8cc534c 633 a->Get(n,temp);
jhnwkmn 0:97a4f8cc534c 634 if(SQVM::IsEqual(temp,val,res) && res) {
jhnwkmn 0:97a4f8cc534c 635 v->Push(n);
jhnwkmn 0:97a4f8cc534c 636 return 1;
jhnwkmn 0:97a4f8cc534c 637 }
jhnwkmn 0:97a4f8cc534c 638 }
jhnwkmn 0:97a4f8cc534c 639 return 0;
jhnwkmn 0:97a4f8cc534c 640 }
jhnwkmn 0:97a4f8cc534c 641
jhnwkmn 0:97a4f8cc534c 642
jhnwkmn 0:97a4f8cc534c 643 bool _sort_compare(HSQUIRRELVM v,SQObjectPtr &a,SQObjectPtr &b,SQInteger func,SQInteger &ret)
jhnwkmn 0:97a4f8cc534c 644 {
jhnwkmn 0:97a4f8cc534c 645 if(func < 0) {
jhnwkmn 0:97a4f8cc534c 646 if(!v->ObjCmp(a,b,ret)) return false;
jhnwkmn 0:97a4f8cc534c 647 }
jhnwkmn 0:97a4f8cc534c 648 else {
jhnwkmn 0:97a4f8cc534c 649 SQInteger top = sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 650 sq_push(v, func);
jhnwkmn 0:97a4f8cc534c 651 sq_pushroottable(v);
jhnwkmn 0:97a4f8cc534c 652 v->Push(a);
jhnwkmn 0:97a4f8cc534c 653 v->Push(b);
jhnwkmn 0:97a4f8cc534c 654 if(SQ_FAILED(sq_call(v, 3, SQTrue, SQFalse))) {
jhnwkmn 0:97a4f8cc534c 655 if(!sq_isstring( v->_lasterror))
jhnwkmn 0:97a4f8cc534c 656 v->Raise_Error(_SC("compare func failed"));
jhnwkmn 0:97a4f8cc534c 657 return false;
jhnwkmn 0:97a4f8cc534c 658 }
jhnwkmn 0:97a4f8cc534c 659 if(SQ_FAILED(sq_getinteger(v, -1, &ret))) {
jhnwkmn 0:97a4f8cc534c 660 v->Raise_Error(_SC("numeric value expected as return value of the compare function"));
jhnwkmn 0:97a4f8cc534c 661 return false;
jhnwkmn 0:97a4f8cc534c 662 }
jhnwkmn 0:97a4f8cc534c 663 sq_settop(v, top);
jhnwkmn 0:97a4f8cc534c 664 return true;
jhnwkmn 0:97a4f8cc534c 665 }
jhnwkmn 0:97a4f8cc534c 666 return true;
jhnwkmn 0:97a4f8cc534c 667 }
jhnwkmn 0:97a4f8cc534c 668
jhnwkmn 0:97a4f8cc534c 669 bool _hsort_sift_down(HSQUIRRELVM v,SQArray *arr, SQInteger root, SQInteger bottom, SQInteger func)
jhnwkmn 0:97a4f8cc534c 670 {
jhnwkmn 0:97a4f8cc534c 671 SQInteger maxChild;
jhnwkmn 0:97a4f8cc534c 672 SQInteger done = 0;
jhnwkmn 0:97a4f8cc534c 673 SQInteger ret;
jhnwkmn 0:97a4f8cc534c 674 SQInteger root2;
jhnwkmn 0:97a4f8cc534c 675 while (((root2 = root * 2) <= bottom) && (!done))
jhnwkmn 0:97a4f8cc534c 676 {
jhnwkmn 0:97a4f8cc534c 677 if (root2 == bottom) {
jhnwkmn 0:97a4f8cc534c 678 maxChild = root2;
jhnwkmn 0:97a4f8cc534c 679 }
jhnwkmn 0:97a4f8cc534c 680 else {
jhnwkmn 0:97a4f8cc534c 681 if(!_sort_compare(v,arr->_values[root2],arr->_values[root2 + 1],func,ret))
jhnwkmn 0:97a4f8cc534c 682 return false;
jhnwkmn 0:97a4f8cc534c 683 if (ret > 0) {
jhnwkmn 0:97a4f8cc534c 684 maxChild = root2;
jhnwkmn 0:97a4f8cc534c 685 }
jhnwkmn 0:97a4f8cc534c 686 else {
jhnwkmn 0:97a4f8cc534c 687 maxChild = root2 + 1;
jhnwkmn 0:97a4f8cc534c 688 }
jhnwkmn 0:97a4f8cc534c 689 }
jhnwkmn 0:97a4f8cc534c 690
jhnwkmn 0:97a4f8cc534c 691 if(!_sort_compare(v,arr->_values[root],arr->_values[maxChild],func,ret))
jhnwkmn 0:97a4f8cc534c 692 return false;
jhnwkmn 0:97a4f8cc534c 693 if (ret < 0) {
jhnwkmn 0:97a4f8cc534c 694 if (root == maxChild) {
jhnwkmn 0:97a4f8cc534c 695 v->Raise_Error(_SC("inconsistent compare function"));
jhnwkmn 0:97a4f8cc534c 696 return false; // We'd be swapping ourselve. The compare function is incorrect
jhnwkmn 0:97a4f8cc534c 697 }
jhnwkmn 0:97a4f8cc534c 698
jhnwkmn 0:97a4f8cc534c 699 _Swap(arr->_values[root],arr->_values[maxChild]);
jhnwkmn 0:97a4f8cc534c 700 root = maxChild;
jhnwkmn 0:97a4f8cc534c 701 }
jhnwkmn 0:97a4f8cc534c 702 else {
jhnwkmn 0:97a4f8cc534c 703 done = 1;
jhnwkmn 0:97a4f8cc534c 704 }
jhnwkmn 0:97a4f8cc534c 705 }
jhnwkmn 0:97a4f8cc534c 706 return true;
jhnwkmn 0:97a4f8cc534c 707 }
jhnwkmn 0:97a4f8cc534c 708
jhnwkmn 0:97a4f8cc534c 709 bool _hsort(HSQUIRRELVM v,SQObjectPtr &arr, SQInteger l, SQInteger r,SQInteger func)
jhnwkmn 0:97a4f8cc534c 710 {
jhnwkmn 0:97a4f8cc534c 711 SQArray *a = _array(arr);
jhnwkmn 0:97a4f8cc534c 712 SQInteger i;
jhnwkmn 0:97a4f8cc534c 713 SQInteger array_size = a->Size();
jhnwkmn 0:97a4f8cc534c 714 for (i = (array_size / 2); i >= 0; i--) {
jhnwkmn 0:97a4f8cc534c 715 if(!_hsort_sift_down(v,a, i, array_size - 1,func)) return false;
jhnwkmn 0:97a4f8cc534c 716 }
jhnwkmn 0:97a4f8cc534c 717
jhnwkmn 0:97a4f8cc534c 718 for (i = array_size-1; i >= 1; i--)
jhnwkmn 0:97a4f8cc534c 719 {
jhnwkmn 0:97a4f8cc534c 720 _Swap(a->_values[0],a->_values[i]);
jhnwkmn 0:97a4f8cc534c 721 if(!_hsort_sift_down(v,a, 0, i-1,func)) return false;
jhnwkmn 0:97a4f8cc534c 722 }
jhnwkmn 0:97a4f8cc534c 723 return true;
jhnwkmn 0:97a4f8cc534c 724 }
jhnwkmn 0:97a4f8cc534c 725
jhnwkmn 0:97a4f8cc534c 726 static SQInteger array_sort(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 727 {
jhnwkmn 0:97a4f8cc534c 728 SQInteger func = -1;
jhnwkmn 0:97a4f8cc534c 729 SQObjectPtr &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 730 if(_array(o)->Size() > 1) {
jhnwkmn 0:97a4f8cc534c 731 if(sq_gettop(v) == 2) func = 2;
jhnwkmn 0:97a4f8cc534c 732 if(!_hsort(v, o, 0, _array(o)->Size()-1, func))
jhnwkmn 0:97a4f8cc534c 733 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 734
jhnwkmn 0:97a4f8cc534c 735 }
jhnwkmn 0:97a4f8cc534c 736 return 0;
jhnwkmn 0:97a4f8cc534c 737 }
jhnwkmn 0:97a4f8cc534c 738
jhnwkmn 0:97a4f8cc534c 739 static SQInteger array_slice(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 740 {
jhnwkmn 0:97a4f8cc534c 741 SQInteger sidx,eidx;
jhnwkmn 0:97a4f8cc534c 742 SQObjectPtr o;
jhnwkmn 0:97a4f8cc534c 743 if(get_slice_params(v,sidx,eidx,o)==-1)return -1;
jhnwkmn 0:97a4f8cc534c 744 SQInteger alen = _array(o)->Size();
jhnwkmn 0:97a4f8cc534c 745 if(sidx < 0)sidx = alen + sidx;
jhnwkmn 0:97a4f8cc534c 746 if(eidx < 0)eidx = alen + eidx;
jhnwkmn 0:97a4f8cc534c 747 if(eidx < sidx)return sq_throwerror(v,_SC("wrong indexes"));
jhnwkmn 0:97a4f8cc534c 748 if(eidx > alen)return sq_throwerror(v,_SC("slice out of range"));
jhnwkmn 0:97a4f8cc534c 749 SQArray *arr=SQArray::Create(_ss(v),eidx-sidx);
jhnwkmn 0:97a4f8cc534c 750 SQObjectPtr t;
jhnwkmn 0:97a4f8cc534c 751 SQInteger count=0;
jhnwkmn 0:97a4f8cc534c 752 for(SQInteger i=sidx;i<eidx;i++){
jhnwkmn 0:97a4f8cc534c 753 _array(o)->Get(i,t);
jhnwkmn 0:97a4f8cc534c 754 arr->Set(count++,t);
jhnwkmn 0:97a4f8cc534c 755 }
jhnwkmn 0:97a4f8cc534c 756 v->Push(arr);
jhnwkmn 0:97a4f8cc534c 757 return 1;
jhnwkmn 0:97a4f8cc534c 758
jhnwkmn 0:97a4f8cc534c 759 }
jhnwkmn 0:97a4f8cc534c 760
jhnwkmn 0:97a4f8cc534c 761 SQRegFunction SQSharedState::_array_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 762 {_SC("len"),default_delegate_len,1, _SC("a")},
jhnwkmn 0:97a4f8cc534c 763 {_SC("append"),array_append,2, _SC("a")},
jhnwkmn 0:97a4f8cc534c 764 {_SC("extend"),array_extend,2, _SC("aa")},
jhnwkmn 0:97a4f8cc534c 765 {_SC("push"),array_append,2, _SC("a")},
jhnwkmn 0:97a4f8cc534c 766 {_SC("pop"),array_pop,1, _SC("a")},
jhnwkmn 0:97a4f8cc534c 767 {_SC("top"),array_top,1, _SC("a")},
jhnwkmn 0:97a4f8cc534c 768 {_SC("insert"),array_insert,3, _SC("an")},
jhnwkmn 0:97a4f8cc534c 769 {_SC("remove"),array_remove,2, _SC("an")},
jhnwkmn 0:97a4f8cc534c 770 {_SC("resize"),array_resize,-2, _SC("an")},
jhnwkmn 0:97a4f8cc534c 771 {_SC("reverse"),array_reverse,1, _SC("a")},
jhnwkmn 0:97a4f8cc534c 772 {_SC("sort"),array_sort,-1, _SC("ac")},
jhnwkmn 0:97a4f8cc534c 773 {_SC("slice"),array_slice,-1, _SC("ann")},
jhnwkmn 0:97a4f8cc534c 774 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 775 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 776 {_SC("clear"),obj_clear,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 777 {_SC("map"),array_map,2, _SC("ac")},
jhnwkmn 0:97a4f8cc534c 778 {_SC("apply"),array_apply,2, _SC("ac")},
jhnwkmn 0:97a4f8cc534c 779 {_SC("reduce"),array_reduce,2, _SC("ac")},
jhnwkmn 0:97a4f8cc534c 780 {_SC("filter"),array_filter,2, _SC("ac")},
jhnwkmn 0:97a4f8cc534c 781 {_SC("find"),array_find,2, _SC("a.")},
jhnwkmn 0:97a4f8cc534c 782 {0,0}
jhnwkmn 0:97a4f8cc534c 783 };
jhnwkmn 0:97a4f8cc534c 784
jhnwkmn 0:97a4f8cc534c 785 //STRING DEFAULT DELEGATE//////////////////////////
jhnwkmn 0:97a4f8cc534c 786 static SQInteger string_slice(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 787 {
jhnwkmn 0:97a4f8cc534c 788 SQInteger sidx,eidx;
jhnwkmn 0:97a4f8cc534c 789 SQObjectPtr o;
jhnwkmn 0:97a4f8cc534c 790 if(SQ_FAILED(get_slice_params(v,sidx,eidx,o)))return -1;
jhnwkmn 0:97a4f8cc534c 791 SQInteger slen = _string(o)->_len;
jhnwkmn 0:97a4f8cc534c 792 if(sidx < 0)sidx = slen + sidx;
jhnwkmn 0:97a4f8cc534c 793 if(eidx < 0)eidx = slen + eidx;
jhnwkmn 0:97a4f8cc534c 794 if(eidx < sidx) return sq_throwerror(v,_SC("wrong indexes"));
jhnwkmn 0:97a4f8cc534c 795 if(eidx > slen) return sq_throwerror(v,_SC("slice out of range"));
jhnwkmn 0:97a4f8cc534c 796 v->Push(SQString::Create(_ss(v),&_stringval(o)[sidx],eidx-sidx));
jhnwkmn 0:97a4f8cc534c 797 return 1;
jhnwkmn 0:97a4f8cc534c 798 }
jhnwkmn 0:97a4f8cc534c 799
jhnwkmn 0:97a4f8cc534c 800 static SQInteger string_find(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 801 {
jhnwkmn 0:97a4f8cc534c 802 SQInteger top,start_idx=0;
jhnwkmn 0:97a4f8cc534c 803 const SQChar *str,*substr,*ret;
jhnwkmn 0:97a4f8cc534c 804 if(((top=sq_gettop(v))>1) && SQ_SUCCEEDED(sq_getstring(v,1,&str)) && SQ_SUCCEEDED(sq_getstring(v,2,&substr))){
jhnwkmn 0:97a4f8cc534c 805 if(top>2)sq_getinteger(v,3,&start_idx);
jhnwkmn 0:97a4f8cc534c 806 if((sq_getsize(v,1)>start_idx) && (start_idx>=0)){
jhnwkmn 0:97a4f8cc534c 807 ret=scstrstr(&str[start_idx],substr);
jhnwkmn 0:97a4f8cc534c 808 if(ret){
jhnwkmn 0:97a4f8cc534c 809 sq_pushinteger(v,(SQInteger)(ret-str));
jhnwkmn 0:97a4f8cc534c 810 return 1;
jhnwkmn 0:97a4f8cc534c 811 }
jhnwkmn 0:97a4f8cc534c 812 }
jhnwkmn 0:97a4f8cc534c 813 return 0;
jhnwkmn 0:97a4f8cc534c 814 }
jhnwkmn 0:97a4f8cc534c 815 return sq_throwerror(v,_SC("invalid param"));
jhnwkmn 0:97a4f8cc534c 816 }
jhnwkmn 0:97a4f8cc534c 817
jhnwkmn 0:97a4f8cc534c 818 #define STRING_TOFUNCZ(func) static SQInteger string_##func(HSQUIRRELVM v) \
jhnwkmn 0:97a4f8cc534c 819 { \
jhnwkmn 0:97a4f8cc534c 820 SQObject str=stack_get(v,1); \
jhnwkmn 0:97a4f8cc534c 821 SQInteger len=_string(str)->_len; \
jhnwkmn 0:97a4f8cc534c 822 const SQChar *sThis=_stringval(str); \
jhnwkmn 0:97a4f8cc534c 823 SQChar *sNew=(_ss(v)->GetScratchPad(rsl(len))); \
jhnwkmn 0:97a4f8cc534c 824 for(SQInteger i=0;i<len;i++) sNew[i]=func(sThis[i]); \
jhnwkmn 0:97a4f8cc534c 825 v->Push(SQString::Create(_ss(v),sNew,len)); \
jhnwkmn 0:97a4f8cc534c 826 return 1; \
jhnwkmn 0:97a4f8cc534c 827 }
jhnwkmn 0:97a4f8cc534c 828
jhnwkmn 0:97a4f8cc534c 829
jhnwkmn 0:97a4f8cc534c 830 STRING_TOFUNCZ(tolower)
jhnwkmn 0:97a4f8cc534c 831 STRING_TOFUNCZ(toupper)
jhnwkmn 0:97a4f8cc534c 832
jhnwkmn 0:97a4f8cc534c 833 SQRegFunction SQSharedState::_string_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 834 {_SC("len"),default_delegate_len,1, _SC("s")},
jhnwkmn 0:97a4f8cc534c 835 {_SC("tointeger"),default_delegate_tointeger,1, _SC("s")},
jhnwkmn 0:97a4f8cc534c 836 {_SC("tofloat"),default_delegate_tofloat,1, _SC("s")},
jhnwkmn 0:97a4f8cc534c 837 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 838 {_SC("slice"),string_slice,-1, _SC(" s n n")},
jhnwkmn 0:97a4f8cc534c 839 {_SC("find"),string_find,-2, _SC("s s n ")},
jhnwkmn 0:97a4f8cc534c 840 {_SC("tolower"),string_tolower,1, _SC("s")},
jhnwkmn 0:97a4f8cc534c 841 {_SC("toupper"),string_toupper,1, _SC("s")},
jhnwkmn 0:97a4f8cc534c 842 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 843 {0,0}
jhnwkmn 0:97a4f8cc534c 844 };
jhnwkmn 0:97a4f8cc534c 845
jhnwkmn 0:97a4f8cc534c 846 //INTEGER DEFAULT DELEGATE//////////////////////////
jhnwkmn 0:97a4f8cc534c 847 SQRegFunction SQSharedState::_number_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 848 {_SC("tointeger"),default_delegate_tointeger,1, _SC("n|b")},
jhnwkmn 0:97a4f8cc534c 849 {_SC("tofloat"),default_delegate_tofloat,1, _SC("n|b")},
jhnwkmn 0:97a4f8cc534c 850 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 851 {_SC("tochar"),number_delegate_tochar,1, _SC("n|b")},
jhnwkmn 0:97a4f8cc534c 852 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 853 {0,0}
jhnwkmn 0:97a4f8cc534c 854 };
jhnwkmn 0:97a4f8cc534c 855
jhnwkmn 0:97a4f8cc534c 856 //CLOSURE DEFAULT DELEGATE//////////////////////////
jhnwkmn 0:97a4f8cc534c 857 static SQInteger closure_pcall(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 858 {
jhnwkmn 0:97a4f8cc534c 859 return SQ_SUCCEEDED(sq_call(v,sq_gettop(v)-1,SQTrue,SQFalse))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 860 }
jhnwkmn 0:97a4f8cc534c 861
jhnwkmn 0:97a4f8cc534c 862 static SQInteger closure_call(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 863 {
jhnwkmn 0:97a4f8cc534c 864 return SQ_SUCCEEDED(sq_call(v,sq_gettop(v)-1,SQTrue,SQTrue))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 865 }
jhnwkmn 0:97a4f8cc534c 866
jhnwkmn 0:97a4f8cc534c 867 static SQInteger _closure_acall(HSQUIRRELVM v,SQBool raiseerror)
jhnwkmn 0:97a4f8cc534c 868 {
jhnwkmn 0:97a4f8cc534c 869 SQArray *aparams=_array(stack_get(v,2));
jhnwkmn 0:97a4f8cc534c 870 SQInteger nparams=aparams->Size();
jhnwkmn 0:97a4f8cc534c 871 v->Push(stack_get(v,1));
jhnwkmn 0:97a4f8cc534c 872 for(SQInteger i=0;i<nparams;i++)v->Push(aparams->_values[i]);
jhnwkmn 0:97a4f8cc534c 873 return SQ_SUCCEEDED(sq_call(v,nparams,SQTrue,raiseerror))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 874 }
jhnwkmn 0:97a4f8cc534c 875
jhnwkmn 0:97a4f8cc534c 876 static SQInteger closure_acall(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 877 {
jhnwkmn 0:97a4f8cc534c 878 return _closure_acall(v,SQTrue);
jhnwkmn 0:97a4f8cc534c 879 }
jhnwkmn 0:97a4f8cc534c 880
jhnwkmn 0:97a4f8cc534c 881 static SQInteger closure_pacall(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 882 {
jhnwkmn 0:97a4f8cc534c 883 return _closure_acall(v,SQFalse);
jhnwkmn 0:97a4f8cc534c 884 }
jhnwkmn 0:97a4f8cc534c 885
jhnwkmn 0:97a4f8cc534c 886 static SQInteger closure_bindenv(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 887 {
jhnwkmn 0:97a4f8cc534c 888 if(SQ_FAILED(sq_bindenv(v,1)))
jhnwkmn 0:97a4f8cc534c 889 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 890 return 1;
jhnwkmn 0:97a4f8cc534c 891 }
jhnwkmn 0:97a4f8cc534c 892
jhnwkmn 0:97a4f8cc534c 893 static SQInteger closure_getinfos(HSQUIRRELVM v) {
jhnwkmn 0:97a4f8cc534c 894 SQObject o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 895 SQTable *res = SQTable::Create(_ss(v),4);
jhnwkmn 0:97a4f8cc534c 896 if(type(o) == OT_CLOSURE) {
jhnwkmn 0:97a4f8cc534c 897 SQFunctionProto *f = _closure(o)->_function;
jhnwkmn 0:97a4f8cc534c 898 SQInteger nparams = f->_nparameters + (f->_varparams?1:0);
jhnwkmn 0:97a4f8cc534c 899 SQObjectPtr params = SQArray::Create(_ss(v),nparams);
jhnwkmn 0:97a4f8cc534c 900 SQObjectPtr defparams = SQArray::Create(_ss(v),f->_ndefaultparams);
jhnwkmn 0:97a4f8cc534c 901 for(SQInteger n = 0; n<f->_nparameters; n++) {
jhnwkmn 0:97a4f8cc534c 902 _array(params)->Set((SQInteger)n,f->_parameters[n]);
jhnwkmn 0:97a4f8cc534c 903 }
jhnwkmn 0:97a4f8cc534c 904 for(SQInteger j = 0; j<f->_ndefaultparams; j++) {
jhnwkmn 0:97a4f8cc534c 905 _array(defparams)->Set((SQInteger)j,_closure(o)->_defaultparams[j]);
jhnwkmn 0:97a4f8cc534c 906 }
jhnwkmn 0:97a4f8cc534c 907 if(f->_varparams) {
jhnwkmn 0:97a4f8cc534c 908 _array(params)->Set(nparams-1,SQString::Create(_ss(v),_SC("..."),-1));
jhnwkmn 0:97a4f8cc534c 909 }
jhnwkmn 0:97a4f8cc534c 910 res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),false);
jhnwkmn 0:97a4f8cc534c 911 res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),f->_name);
jhnwkmn 0:97a4f8cc534c 912 res->NewSlot(SQString::Create(_ss(v),_SC("src"),-1),f->_sourcename);
jhnwkmn 0:97a4f8cc534c 913 res->NewSlot(SQString::Create(_ss(v),_SC("parameters"),-1),params);
jhnwkmn 0:97a4f8cc534c 914 res->NewSlot(SQString::Create(_ss(v),_SC("varargs"),-1),f->_varparams);
jhnwkmn 0:97a4f8cc534c 915 res->NewSlot(SQString::Create(_ss(v),_SC("defparams"),-1),defparams);
jhnwkmn 0:97a4f8cc534c 916 }
jhnwkmn 0:97a4f8cc534c 917 else { //OT_NATIVECLOSURE
jhnwkmn 0:97a4f8cc534c 918 SQNativeClosure *nc = _nativeclosure(o);
jhnwkmn 0:97a4f8cc534c 919 res->NewSlot(SQString::Create(_ss(v),_SC("native"),-1),true);
jhnwkmn 0:97a4f8cc534c 920 res->NewSlot(SQString::Create(_ss(v),_SC("name"),-1),nc->_name);
jhnwkmn 0:97a4f8cc534c 921 res->NewSlot(SQString::Create(_ss(v),_SC("paramscheck"),-1),nc->_nparamscheck);
jhnwkmn 0:97a4f8cc534c 922 SQObjectPtr typecheck;
jhnwkmn 0:97a4f8cc534c 923 if(nc->_typecheck.size() > 0) {
jhnwkmn 0:97a4f8cc534c 924 typecheck =
jhnwkmn 0:97a4f8cc534c 925 SQArray::Create(_ss(v), nc->_typecheck.size());
jhnwkmn 0:97a4f8cc534c 926 for(SQUnsignedInteger n = 0; n<nc->_typecheck.size(); n++) {
jhnwkmn 0:97a4f8cc534c 927 _array(typecheck)->Set((SQInteger)n,nc->_typecheck[n]);
jhnwkmn 0:97a4f8cc534c 928 }
jhnwkmn 0:97a4f8cc534c 929 }
jhnwkmn 0:97a4f8cc534c 930 res->NewSlot(SQString::Create(_ss(v),_SC("typecheck"),-1),typecheck);
jhnwkmn 0:97a4f8cc534c 931 }
jhnwkmn 0:97a4f8cc534c 932 v->Push(res);
jhnwkmn 0:97a4f8cc534c 933 return 1;
jhnwkmn 0:97a4f8cc534c 934 }
jhnwkmn 0:97a4f8cc534c 935
jhnwkmn 0:97a4f8cc534c 936
jhnwkmn 0:97a4f8cc534c 937
jhnwkmn 0:97a4f8cc534c 938 SQRegFunction SQSharedState::_closure_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 939 {_SC("call"),closure_call,-1, _SC("c")},
jhnwkmn 0:97a4f8cc534c 940 {_SC("pcall"),closure_pcall,-1, _SC("c")},
jhnwkmn 0:97a4f8cc534c 941 {_SC("acall"),closure_acall,2, _SC("ca")},
jhnwkmn 0:97a4f8cc534c 942 {_SC("pacall"),closure_pacall,2, _SC("ca")},
jhnwkmn 0:97a4f8cc534c 943 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 944 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 945 {_SC("bindenv"),closure_bindenv,2, _SC("c x|y|t")},
jhnwkmn 0:97a4f8cc534c 946 {_SC("getinfos"),closure_getinfos,1, _SC("c")},
jhnwkmn 0:97a4f8cc534c 947 {0,0}
jhnwkmn 0:97a4f8cc534c 948 };
jhnwkmn 0:97a4f8cc534c 949
jhnwkmn 0:97a4f8cc534c 950 //GENERATOR DEFAULT DELEGATE
jhnwkmn 0:97a4f8cc534c 951 static SQInteger generator_getstatus(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 952 {
jhnwkmn 0:97a4f8cc534c 953 SQObject &o=stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 954 switch(_generator(o)->_state){
jhnwkmn 0:97a4f8cc534c 955 case SQGenerator::eSuspended:v->Push(SQString::Create(_ss(v),_SC("suspended")));break;
jhnwkmn 0:97a4f8cc534c 956 case SQGenerator::eRunning:v->Push(SQString::Create(_ss(v),_SC("running")));break;
jhnwkmn 0:97a4f8cc534c 957 case SQGenerator::eDead:v->Push(SQString::Create(_ss(v),_SC("dead")));break;
jhnwkmn 0:97a4f8cc534c 958 }
jhnwkmn 0:97a4f8cc534c 959 return 1;
jhnwkmn 0:97a4f8cc534c 960 }
jhnwkmn 0:97a4f8cc534c 961
jhnwkmn 0:97a4f8cc534c 962 SQRegFunction SQSharedState::_generator_default_delegate_funcz[]={
jhnwkmn 0:97a4f8cc534c 963 {_SC("getstatus"),generator_getstatus,1, _SC("g")},
jhnwkmn 0:97a4f8cc534c 964 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 965 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 966 {0,0}
jhnwkmn 0:97a4f8cc534c 967 };
jhnwkmn 0:97a4f8cc534c 968
jhnwkmn 0:97a4f8cc534c 969 //THREAD DEFAULT DELEGATE
jhnwkmn 0:97a4f8cc534c 970 static SQInteger thread_call(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 971 {
jhnwkmn 0:97a4f8cc534c 972 SQObjectPtr o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 973 if(type(o) == OT_THREAD) {
jhnwkmn 0:97a4f8cc534c 974 SQInteger nparams = sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 975 _thread(o)->Push(_thread(o)->_roottable);
jhnwkmn 0:97a4f8cc534c 976 for(SQInteger i = 2; i<(nparams+1); i++)
jhnwkmn 0:97a4f8cc534c 977 sq_move(_thread(o),v,i);
jhnwkmn 0:97a4f8cc534c 978 if(SQ_SUCCEEDED(sq_call(_thread(o),nparams,SQTrue,SQTrue))) {
jhnwkmn 0:97a4f8cc534c 979 sq_move(v,_thread(o),-1);
jhnwkmn 0:97a4f8cc534c 980 sq_pop(_thread(o),1);
jhnwkmn 0:97a4f8cc534c 981 return 1;
jhnwkmn 0:97a4f8cc534c 982 }
jhnwkmn 0:97a4f8cc534c 983 v->_lasterror = _thread(o)->_lasterror;
jhnwkmn 0:97a4f8cc534c 984 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 985 }
jhnwkmn 0:97a4f8cc534c 986 return sq_throwerror(v,_SC("wrong parameter"));
jhnwkmn 0:97a4f8cc534c 987 }
jhnwkmn 0:97a4f8cc534c 988
jhnwkmn 0:97a4f8cc534c 989 static SQInteger thread_wakeup(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 990 {
jhnwkmn 0:97a4f8cc534c 991 SQObjectPtr o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 992 if(type(o) == OT_THREAD) {
jhnwkmn 0:97a4f8cc534c 993 SQVM *thread = _thread(o);
jhnwkmn 0:97a4f8cc534c 994 SQInteger state = sq_getvmstate(thread);
jhnwkmn 0:97a4f8cc534c 995 if(state != SQ_VMSTATE_SUSPENDED) {
jhnwkmn 0:97a4f8cc534c 996 switch(state) {
jhnwkmn 0:97a4f8cc534c 997 case SQ_VMSTATE_IDLE:
jhnwkmn 0:97a4f8cc534c 998 return sq_throwerror(v,_SC("cannot wakeup a idle thread"));
jhnwkmn 0:97a4f8cc534c 999 break;
jhnwkmn 0:97a4f8cc534c 1000 case SQ_VMSTATE_RUNNING:
jhnwkmn 0:97a4f8cc534c 1001 return sq_throwerror(v,_SC("cannot wakeup a running thread"));
jhnwkmn 0:97a4f8cc534c 1002 break;
jhnwkmn 0:97a4f8cc534c 1003 }
jhnwkmn 0:97a4f8cc534c 1004 }
jhnwkmn 0:97a4f8cc534c 1005
jhnwkmn 0:97a4f8cc534c 1006 SQInteger wakeupret = sq_gettop(v)>1?1:0;
jhnwkmn 0:97a4f8cc534c 1007 if(wakeupret) {
jhnwkmn 0:97a4f8cc534c 1008 sq_move(thread,v,2);
jhnwkmn 0:97a4f8cc534c 1009 }
jhnwkmn 0:97a4f8cc534c 1010 if(SQ_SUCCEEDED(sq_wakeupvm(thread,wakeupret,SQTrue,SQTrue,SQFalse))) {
jhnwkmn 0:97a4f8cc534c 1011 sq_move(v,thread,-1);
jhnwkmn 0:97a4f8cc534c 1012 sq_pop(thread,1); //pop retval
jhnwkmn 0:97a4f8cc534c 1013 if(sq_getvmstate(thread) == SQ_VMSTATE_IDLE) {
jhnwkmn 0:97a4f8cc534c 1014 sq_settop(thread,1); //pop roottable
jhnwkmn 0:97a4f8cc534c 1015 }
jhnwkmn 0:97a4f8cc534c 1016 return 1;
jhnwkmn 0:97a4f8cc534c 1017 }
jhnwkmn 0:97a4f8cc534c 1018 sq_settop(thread,1);
jhnwkmn 0:97a4f8cc534c 1019 v->_lasterror = thread->_lasterror;
jhnwkmn 0:97a4f8cc534c 1020 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1021 }
jhnwkmn 0:97a4f8cc534c 1022 return sq_throwerror(v,_SC("wrong parameter"));
jhnwkmn 0:97a4f8cc534c 1023 }
jhnwkmn 0:97a4f8cc534c 1024
jhnwkmn 0:97a4f8cc534c 1025 static SQInteger thread_getstatus(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1026 {
jhnwkmn 0:97a4f8cc534c 1027 SQObjectPtr &o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 1028 switch(sq_getvmstate(_thread(o))) {
jhnwkmn 0:97a4f8cc534c 1029 case SQ_VMSTATE_IDLE:
jhnwkmn 0:97a4f8cc534c 1030 sq_pushstring(v,_SC("idle"),-1);
jhnwkmn 0:97a4f8cc534c 1031 break;
jhnwkmn 0:97a4f8cc534c 1032 case SQ_VMSTATE_RUNNING:
jhnwkmn 0:97a4f8cc534c 1033 sq_pushstring(v,_SC("running"),-1);
jhnwkmn 0:97a4f8cc534c 1034 break;
jhnwkmn 0:97a4f8cc534c 1035 case SQ_VMSTATE_SUSPENDED:
jhnwkmn 0:97a4f8cc534c 1036 sq_pushstring(v,_SC("suspended"),-1);
jhnwkmn 0:97a4f8cc534c 1037 break;
jhnwkmn 0:97a4f8cc534c 1038 default:
jhnwkmn 0:97a4f8cc534c 1039 return sq_throwerror(v,_SC("internal VM error"));
jhnwkmn 0:97a4f8cc534c 1040 }
jhnwkmn 0:97a4f8cc534c 1041 return 1;
jhnwkmn 0:97a4f8cc534c 1042 }
jhnwkmn 0:97a4f8cc534c 1043
jhnwkmn 0:97a4f8cc534c 1044 static SQInteger thread_getstackinfos(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1045 {
jhnwkmn 0:97a4f8cc534c 1046 SQObjectPtr o = stack_get(v,1);
jhnwkmn 0:97a4f8cc534c 1047 if(type(o) == OT_THREAD) {
jhnwkmn 0:97a4f8cc534c 1048 SQVM *thread = _thread(o);
jhnwkmn 0:97a4f8cc534c 1049 SQInteger threadtop = sq_gettop(thread);
jhnwkmn 0:97a4f8cc534c 1050 SQInteger level;
jhnwkmn 0:97a4f8cc534c 1051 sq_getinteger(v,-1,&level);
jhnwkmn 0:97a4f8cc534c 1052 SQRESULT res = __getcallstackinfos(thread,level);
jhnwkmn 0:97a4f8cc534c 1053 if(SQ_FAILED(res))
jhnwkmn 0:97a4f8cc534c 1054 {
jhnwkmn 0:97a4f8cc534c 1055 sq_settop(thread,threadtop);
jhnwkmn 0:97a4f8cc534c 1056 if(type(thread->_lasterror) == OT_STRING) {
jhnwkmn 0:97a4f8cc534c 1057 sq_throwerror(v,_stringval(thread->_lasterror));
jhnwkmn 0:97a4f8cc534c 1058 }
jhnwkmn 0:97a4f8cc534c 1059 else {
jhnwkmn 0:97a4f8cc534c 1060 sq_throwerror(v,_SC("unknown error"));
jhnwkmn 0:97a4f8cc534c 1061 }
jhnwkmn 0:97a4f8cc534c 1062 }
jhnwkmn 0:97a4f8cc534c 1063 if(res > 0) {
jhnwkmn 0:97a4f8cc534c 1064 //some result
jhnwkmn 0:97a4f8cc534c 1065 sq_move(v,thread,-1);
jhnwkmn 0:97a4f8cc534c 1066 sq_settop(thread,threadtop);
jhnwkmn 0:97a4f8cc534c 1067 return 1;
jhnwkmn 0:97a4f8cc534c 1068 }
jhnwkmn 0:97a4f8cc534c 1069 //no result
jhnwkmn 0:97a4f8cc534c 1070 sq_settop(thread,threadtop);
jhnwkmn 0:97a4f8cc534c 1071 return 0;
jhnwkmn 0:97a4f8cc534c 1072
jhnwkmn 0:97a4f8cc534c 1073 }
jhnwkmn 0:97a4f8cc534c 1074 return sq_throwerror(v,_SC("wrong parameter"));
jhnwkmn 0:97a4f8cc534c 1075 }
jhnwkmn 0:97a4f8cc534c 1076
jhnwkmn 0:97a4f8cc534c 1077 SQRegFunction SQSharedState::_thread_default_delegate_funcz[] = {
jhnwkmn 0:97a4f8cc534c 1078 {_SC("call"), thread_call, -1, _SC("v")},
jhnwkmn 0:97a4f8cc534c 1079 {_SC("wakeup"), thread_wakeup, -1, _SC("v")},
jhnwkmn 0:97a4f8cc534c 1080 {_SC("getstatus"), thread_getstatus, 1, _SC("v")},
jhnwkmn 0:97a4f8cc534c 1081 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 1082 {_SC("getstackinfos"),thread_getstackinfos,2, _SC("vn")},
jhnwkmn 0:97a4f8cc534c 1083 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 1084 {0,0},
jhnwkmn 0:97a4f8cc534c 1085 };
jhnwkmn 0:97a4f8cc534c 1086
jhnwkmn 0:97a4f8cc534c 1087 static SQInteger class_getattributes(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1088 {
jhnwkmn 0:97a4f8cc534c 1089 return SQ_SUCCEEDED(sq_getattributes(v,-2))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1090 }
jhnwkmn 0:97a4f8cc534c 1091
jhnwkmn 0:97a4f8cc534c 1092 static SQInteger class_setattributes(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1093 {
jhnwkmn 0:97a4f8cc534c 1094 return SQ_SUCCEEDED(sq_setattributes(v,-3))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1095 }
jhnwkmn 0:97a4f8cc534c 1096
jhnwkmn 0:97a4f8cc534c 1097 static SQInteger class_instance(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1098 {
jhnwkmn 0:97a4f8cc534c 1099 return SQ_SUCCEEDED(sq_createinstance(v,-1))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1100 }
jhnwkmn 0:97a4f8cc534c 1101
jhnwkmn 0:97a4f8cc534c 1102 static SQInteger class_getbase(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1103 {
jhnwkmn 0:97a4f8cc534c 1104 return SQ_SUCCEEDED(sq_getbase(v,-1))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1105 }
jhnwkmn 0:97a4f8cc534c 1106
jhnwkmn 0:97a4f8cc534c 1107 static SQInteger class_newmember(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1108 {
jhnwkmn 0:97a4f8cc534c 1109 SQInteger top = sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 1110 SQBool bstatic = SQFalse;
jhnwkmn 0:97a4f8cc534c 1111 if(top == 5)
jhnwkmn 0:97a4f8cc534c 1112 {
jhnwkmn 0:97a4f8cc534c 1113 sq_tobool(v,-1,&bstatic);
jhnwkmn 0:97a4f8cc534c 1114 sq_pop(v,1);
jhnwkmn 0:97a4f8cc534c 1115 }
jhnwkmn 0:97a4f8cc534c 1116
jhnwkmn 0:97a4f8cc534c 1117 if(top < 4) {
jhnwkmn 0:97a4f8cc534c 1118 sq_pushnull(v);
jhnwkmn 0:97a4f8cc534c 1119 }
jhnwkmn 0:97a4f8cc534c 1120 return SQ_SUCCEEDED(sq_newmember(v,-4,bstatic))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1121 }
jhnwkmn 0:97a4f8cc534c 1122
jhnwkmn 0:97a4f8cc534c 1123 static SQInteger class_rawnewmember(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1124 {
jhnwkmn 0:97a4f8cc534c 1125 SQInteger top = sq_gettop(v);
jhnwkmn 0:97a4f8cc534c 1126 SQBool bstatic = SQFalse;
jhnwkmn 0:97a4f8cc534c 1127 if(top == 5)
jhnwkmn 0:97a4f8cc534c 1128 {
jhnwkmn 0:97a4f8cc534c 1129 sq_tobool(v,-1,&bstatic);
jhnwkmn 0:97a4f8cc534c 1130 sq_pop(v,1);
jhnwkmn 0:97a4f8cc534c 1131 }
jhnwkmn 0:97a4f8cc534c 1132
jhnwkmn 0:97a4f8cc534c 1133 if(top < 4) {
jhnwkmn 0:97a4f8cc534c 1134 sq_pushnull(v);
jhnwkmn 0:97a4f8cc534c 1135 }
jhnwkmn 0:97a4f8cc534c 1136 return SQ_SUCCEEDED(sq_rawnewmember(v,-4,bstatic))?1:SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1137 }
jhnwkmn 0:97a4f8cc534c 1138
jhnwkmn 0:97a4f8cc534c 1139 SQRegFunction SQSharedState::_class_default_delegate_funcz[] = {
jhnwkmn 0:97a4f8cc534c 1140 {_SC("getattributes"), class_getattributes, 2, _SC("y.")},
jhnwkmn 0:97a4f8cc534c 1141 {_SC("setattributes"), class_setattributes, 3, _SC("y..")},
jhnwkmn 0:97a4f8cc534c 1142 {_SC("rawget"),container_rawget,2, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1143 {_SC("rawset"),container_rawset,3, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1144 {_SC("rawin"),container_rawexists,2, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1145 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 1146 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 1147 {_SC("instance"),class_instance,1, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1148 {_SC("getbase"),class_getbase,1, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1149 {_SC("newmember"),class_newmember,-3, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1150 {_SC("rawnewmember"),class_rawnewmember,-3, _SC("y")},
jhnwkmn 0:97a4f8cc534c 1151 {0,0}
jhnwkmn 0:97a4f8cc534c 1152 };
jhnwkmn 0:97a4f8cc534c 1153
jhnwkmn 0:97a4f8cc534c 1154
jhnwkmn 0:97a4f8cc534c 1155 static SQInteger instance_getclass(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1156 {
jhnwkmn 0:97a4f8cc534c 1157 if(SQ_SUCCEEDED(sq_getclass(v,1)))
jhnwkmn 0:97a4f8cc534c 1158 return 1;
jhnwkmn 0:97a4f8cc534c 1159 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1160 }
jhnwkmn 0:97a4f8cc534c 1161
jhnwkmn 0:97a4f8cc534c 1162 SQRegFunction SQSharedState::_instance_default_delegate_funcz[] = {
jhnwkmn 0:97a4f8cc534c 1163 {_SC("getclass"), instance_getclass, 1, _SC("x")},
jhnwkmn 0:97a4f8cc534c 1164 {_SC("rawget"),container_rawget,2, _SC("x")},
jhnwkmn 0:97a4f8cc534c 1165 {_SC("rawset"),container_rawset,3, _SC("x")},
jhnwkmn 0:97a4f8cc534c 1166 {_SC("rawin"),container_rawexists,2, _SC("x")},
jhnwkmn 0:97a4f8cc534c 1167 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 1168 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 1169 {0,0}
jhnwkmn 0:97a4f8cc534c 1170 };
jhnwkmn 0:97a4f8cc534c 1171
jhnwkmn 0:97a4f8cc534c 1172 static SQInteger weakref_ref(HSQUIRRELVM v)
jhnwkmn 0:97a4f8cc534c 1173 {
jhnwkmn 0:97a4f8cc534c 1174 if(SQ_FAILED(sq_getweakrefval(v,1)))
jhnwkmn 0:97a4f8cc534c 1175 return SQ_ERROR;
jhnwkmn 0:97a4f8cc534c 1176 return 1;
jhnwkmn 0:97a4f8cc534c 1177 }
jhnwkmn 0:97a4f8cc534c 1178
jhnwkmn 0:97a4f8cc534c 1179 SQRegFunction SQSharedState::_weakref_default_delegate_funcz[] = {
jhnwkmn 0:97a4f8cc534c 1180 {_SC("ref"),weakref_ref,1, _SC("r")},
jhnwkmn 0:97a4f8cc534c 1181 {_SC("weakref"),obj_delegate_weakref,1, NULL },
jhnwkmn 0:97a4f8cc534c 1182 {_SC("tostring"),default_delegate_tostring,1, _SC(".")},
jhnwkmn 0:97a4f8cc534c 1183 {0,0}
jhnwkmn 0:97a4f8cc534c 1184 };
jhnwkmn 0:97a4f8cc534c 1185