mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-22 01:57:14 +02:00
Back port changes to squirrel library. Separate mdoule speciffic changes and/or additions to squirrel into their own files.
This commit is contained in:
21
external/Squirrel/Lib/sqstdaux.cpp
vendored
21
external/Squirrel/Lib/sqstdaux.cpp
vendored
@ -1,7 +1,9 @@
|
||||
/* see copyright notice in squirrel.h */
|
||||
#include <squirrel.h>
|
||||
#include <sqstdaux.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
void sqstd_printcallstack(HSQUIRRELVM v)
|
||||
{
|
||||
@ -128,3 +130,22 @@ void sqstd_seterrorhandlers(HSQUIRRELVM v)
|
||||
sq_newclosure(v,_sqstd_aux_printerror,0);
|
||||
sq_seterrorhandler(v);
|
||||
}
|
||||
|
||||
SQRESULT sqstd_throwerrorf(HSQUIRRELVM v,const SQChar *err,...)
|
||||
{
|
||||
SQInteger n=256;
|
||||
va_list args;
|
||||
begin:
|
||||
va_start(args,err);
|
||||
SQChar *b=sq_getscratchpad(v,n);
|
||||
SQInteger r=scvsprintf(b,n,err,args);
|
||||
va_end(args);
|
||||
if (r>=n) {
|
||||
n=r+1;//required+null
|
||||
goto begin;
|
||||
} else if (r<0) {
|
||||
return sq_throwerror(v,_SC("@failed to generate formatted error message"));
|
||||
} else {
|
||||
return sq_throwerror(v,b);
|
||||
}
|
||||
}
|
||||
|
20
external/Squirrel/Lib/sqstdstring.cpp
vendored
20
external/Squirrel/Lib/sqstdstring.cpp
vendored
@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define MAX_FORMAT_LEN 20
|
||||
#define MAX_WFORMAT_LEN 3
|
||||
@ -153,6 +154,25 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
|
||||
return SQ_OK;
|
||||
}
|
||||
|
||||
void sqstd_pushstringf(HSQUIRRELVM v,const SQChar *s,...)
|
||||
{
|
||||
SQInteger n=256;
|
||||
va_list args;
|
||||
begin:
|
||||
va_start(args,s);
|
||||
SQChar *b=sq_getscratchpad(v,n);
|
||||
SQInteger r=scvsprintf(b,n,s,args);
|
||||
va_end(args);
|
||||
if (r>=n) {
|
||||
n=r+1;//required+null
|
||||
goto begin;
|
||||
} else if (r<0) {
|
||||
sq_pushnull(v);
|
||||
} else {
|
||||
sq_pushstring(v,b,r);
|
||||
}
|
||||
}
|
||||
|
||||
static SQInteger _string_printf(HSQUIRRELVM v)
|
||||
{
|
||||
SQChar *dest = NULL;
|
||||
|
Reference in New Issue
Block a user