Merge pull request #45 from zeromus/pstring

feature: sq_getstringandsize()
This commit is contained in:
Alberto Demichelis 2016-05-16 01:42:00 +08:00
commit 8ca802658c
4 changed files with 26 additions and 0 deletions

View File

@ -243,6 +243,21 @@ gets a pointer to the string at the idx position in the stack.
.. _sq_getstringandsize:
.. c:function:: SQRESULT sq_getstringandsize(HSQUIRRELVM v, SQInteger idx, const SQChar ** c, SQInteger* size)
:param HSQUIRRELVM v: the target VM
:param SQInteger idx: an index in the stack
:param const SQChar ** c: a pointer to the pointer that will point to the string
:param SQInteger * size: a pointer to a SQInteger which will receive the size of the string
:returns: a SQRESULT
gets a pointer to the string at the idx position in the stack; additionally retrieves its size.
.. _sq_getthread:
.. c:function:: SQRESULT sq_getthread(HSQUIRRELVM v, SQInteger idx, HSQUIRRELVM* v)

View File

@ -92,6 +92,7 @@ the result can be one of the following values: ::
The following functions convert a squirrel value in the stack to a C value::
SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger size);
SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);

View File

@ -258,6 +258,7 @@ SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
SQUIRREL_API SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size);
SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);

View File

@ -680,6 +680,15 @@ SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b)
return SQ_ERROR;
}
SQRESULT sq_getstringandsize(HSQUIRRELVM v,SQInteger idx,const SQChar **c,SQInteger *size)
{
SQObjectPtr *o = NULL;
_GETSAFE_OBJ(v, idx, OT_STRING,o);
*c = _stringval(*o);
*size = _stringlen(*o);
return SQ_OK;
}
SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c)
{
SQObjectPtr *o = NULL;