add a printf function to the string stdlib, so we can avoid having to write print(format( all the time. it should be a little more lean than writing that function in lua yourself (can work entirely from scratchpad this way).

This commit is contained in:
zeromus 2016-05-12 11:46:04 -05:00
parent 16ab1fd6c0
commit e0f0e180a3

View File

@ -150,6 +150,19 @@ SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen
return SQ_OK;
}
static SQInteger _string_printf(HSQUIRRELVM v)
{
SQChar *dest = NULL;
SQInteger length = 0;
if(SQ_FAILED(sqstd_format(v,2,&length,&dest)))
return -1;
SQPRINTFUNCTION printfunc = sq_getprintfunc(v);
if(printfunc) printfunc(v,dest);
return 0;
}
static SQInteger _string_format(HSQUIRRELVM v)
{
SQChar *dest = NULL;
@ -459,6 +472,7 @@ static const SQRegFunction rexobj_funcs[]={
#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_string_##name,nparams,pmask}
static const SQRegFunction stringlib_funcs[]={
_DECL_FUNC(format,-2,_SC(".s")),
_DECL_FUNC(printf,-2,_SC(".s")),
_DECL_FUNC(strip,2,_SC(".s")),
_DECL_FUNC(lstrip,2,_SC(".s")),
_DECL_FUNC(rstrip,2,_SC(".s")),