(svn r17195) -Update: squirrel to 2.2.3 stable

This commit is contained in:
yexo
2009-08-15 21:21:52 +00:00
parent 75f8a9db0a
commit 03d711add3
17 changed files with 177 additions and 35 deletions

View File

@@ -79,15 +79,16 @@ static void _append_string(SQInteger &i, SQChar *dest, SQInteger allocated, cons
va_end(va);
}
static SQInteger _string_format(HSQUIRRELVM v)
SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output)
{
const SQChar *format;
SQChar *dest;
SQChar fmt[MAX_FORMAT_LEN];
sq_getstring(v,2,&format);
SQInteger allocated = (sq_getsize(v,2)+1)*sizeof(SQChar);
sq_getstring(v,nformatstringidx,&format);
SQInteger allocated = (sq_getsize(v,nformatstringidx)+2)*sizeof(SQChar);
dest = sq_getscratchpad(v,allocated);
SQInteger n = 0,i = 0, nparam = 3, w = 0;
SQInteger n = 0,i = 0, nparam = nformatstringidx+1, w = 0;
while(format[n] != '\0') {
if(format[n] != '%') {
assert(i < allocated);
@@ -132,7 +133,7 @@ static SQInteger _string_format(HSQUIRRELVM v)
return sq_throwerror(v,_SC("invalid format"));
}
n++;
allocated += addlen;
allocated += addlen + sizeof(SQChar);
dest = sq_getscratchpad(v,allocated);
switch(valtype) {
case 's': _append_string(i,dest,allocated,fmt,ts); break;
@@ -142,7 +143,19 @@ static SQInteger _string_format(HSQUIRRELVM v)
nparam ++;
}
}
sq_pushstring(v,dest,i);
*outlen = i;
dest[i] = '\0';
*output = dest;
return SQ_OK;
}
static SQInteger _string_format(HSQUIRRELVM v)
{
SQChar *dest = NULL;
SQInteger length = 0;
if(SQ_FAILED(sqstd_format(v,2,&length,&dest)))
return -1;
sq_pushstring(v,dest,length);
return 1;
}