diff --git a/doc/source/reference/api/object_creation_and_handling.rst b/doc/source/reference/api/object_creation_and_handling.rst index bc9bdad..9cc60d2 100644 --- a/doc/source/reference/api/object_creation_and_handling.rst +++ b/doc/source/reference/api/object_creation_and_handling.rst @@ -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) diff --git a/doc/source/reference/embedding/the_stack.rst b/doc/source/reference/embedding/the_stack.rst index 5355e8f..9c5f9ae 100644 --- a/doc/source/reference/embedding/the_stack.rst +++ b/doc/source/reference/embedding/the_stack.rst @@ -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); diff --git a/include/squirrel.h b/include/squirrel.h index 221a0ae..830a587 100644 --- a/include/squirrel.h +++ b/include/squirrel.h @@ -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); diff --git a/squirrel/sqapi.cpp b/squirrel/sqapi.cpp index d7b49eb..a304f6e 100644 --- a/squirrel/sqapi.cpp +++ b/squirrel/sqapi.cpp @@ -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;