summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel/sqstdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/squirrel/sqstdlib')
-rw-r--r--src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp5
-rw-r--r--src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp25
2 files changed, 22 insertions, 8 deletions
diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
index 65c9070b3..e1f93cbf7 100644
--- a/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
+++ b/src/3rdparty/squirrel/sqstdlib/sqstdaux.cpp
@@ -9,6 +9,7 @@ void sqstd_printcallstack(HSQUIRRELVM v)
if(pf) {
SQStackInfos si;
SQInteger i;
+ SQBool b;
SQFloat f;
const SQChar *s;
SQInteger level=1; //1 is to skip this function that is level 0
@@ -83,8 +84,8 @@ void sqstd_printcallstack(HSQUIRRELVM v)
pf(v,_SC("[%s] WEAKREF\n"),name);
break;
case OT_BOOL:{
- sq_getinteger(v,-1,&i);
- pf(v,_SC("[%s] %s\n"),name,i?_SC("true"):_SC("false"));
+ sq_getbool(v,-1,&b);
+ pf(v,_SC("[%s] %s\n"),name,b?_SC("true"):_SC("false"));
}
break;
default: assert(0); break;
diff --git a/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp b/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp
index 00b1667e0..681029aa7 100644
--- a/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp
+++ b/src/3rdparty/squirrel/sqstdlib/sqstdstring.cpp
@@ -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;
}