From e0f0e180a37d248816136cfb5d6161dcca441885 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 12 May 2016 11:46:04 -0500 Subject: [PATCH] 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). --- sqstdlib/sqstdstring.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sqstdlib/sqstdstring.cpp b/sqstdlib/sqstdstring.cpp index 5b8074b..9e42dba 100644 --- a/sqstdlib/sqstdstring.cpp +++ b/sqstdlib/sqstdstring.cpp @@ -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")),