mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Add sq_arrayreserve extension to squirrel API.
This commit is contained in:
parent
4a6bfc086c
commit
1c84c7f35a
1
vendor/Squirrel/include/squirrelex.h
vendored
1
vendor/Squirrel/include/squirrelex.h
vendored
@ -15,6 +15,7 @@ SQUIRREL_API SQRESULT sq_throwerrorf(HSQUIRRELVM v,const SQChar *err,...);
|
||||
SQUIRREL_API SQRESULT sq_pushstringf(HSQUIRRELVM v,const SQChar *s,...);
|
||||
SQUIRREL_API SQRESULT sq_vpushstringf(HSQUIRRELVM v,const SQChar *s,va_list l);
|
||||
SQUIRREL_API SQRESULT sq_getnativeclosurepointer(HSQUIRRELVM v,SQInteger idx,SQFUNCTION *f);
|
||||
SQUIRREL_API SQRESULT sq_arrayreserve(HSQUIRRELVM v,SQInteger idx,SQInteger newcap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
|
30
vendor/Squirrel/sqapiex.cpp
vendored
30
vendor/Squirrel/sqapiex.cpp
vendored
@ -16,6 +16,24 @@
|
||||
#include <squirrelex.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define _GETSAFE_OBJ(v,idx,type,o) { if(!sq_aux_gettypedarg(v,idx,type,&o)) return SQ_ERROR; }
|
||||
|
||||
#define sq_aux_paramscheck(v,count) \
|
||||
{ \
|
||||
if(sq_gettop(v) < count){ v->Raise_Error(_SC("not enough params in the stack")); return SQ_ERROR; }\
|
||||
}
|
||||
|
||||
static bool sq_aux_gettypedarg(HSQUIRRELVM v,SQInteger idx,SQObjectType type,SQObjectPtr **o)
|
||||
{
|
||||
*o = &stack_get(v,idx);
|
||||
if(sq_type(**o) != type){
|
||||
SQObjectPtr oval = v->PrintObjVal(**o);
|
||||
v->Raise_Error(_SC("wrong argument type, expected '%s' got '%.50s'"),IdType2Name(type),_stringval(oval));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SQRESULT sq_throwerrorf(HSQUIRRELVM v,const SQChar *err,...)
|
||||
{
|
||||
SQInteger n=256;
|
||||
@ -89,3 +107,15 @@ SQRESULT sq_getnativeclosurepointer(HSQUIRRELVM v,SQInteger idx,SQFUNCTION *f)
|
||||
}
|
||||
return sq_throwerror(v,_SC("the object is not a native closure"));
|
||||
}
|
||||
|
||||
SQRESULT sq_arrayreserve(HSQUIRRELVM v,SQInteger idx,SQInteger newcap)
|
||||
{
|
||||
sq_aux_paramscheck(v,1);
|
||||
SQObjectPtr *arr;
|
||||
_GETSAFE_OBJ(v, idx, OT_ARRAY,arr);
|
||||
if(newcap >= 0) {
|
||||
_array(*arr)->Reserve(newcap);
|
||||
return SQ_OK;
|
||||
}
|
||||
return sq_throwerror(v,_SC("negative capacity"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user