1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Implement a formatted Squirrel error throwing utility.

This commit is contained in:
Sandu Liviu Catalin 2017-06-16 02:23:24 +03:00
parent e8027dcb3d
commit f048950d20
2 changed files with 22 additions and 0 deletions

View File

@ -98,6 +98,11 @@ CSStr ToStrF(CCStr str, ...);
*/
CSStr ToStringF(CCStr str, ...);
/* ------------------------------------------------------------------------------------------------
* Generate a formatted string and throw it as a squirrel exception.
*/
SQRESULT SqThrowErrorF(HSQUIRRELVM vm, CCStr str, ...);
/* ------------------------------------------------------------------------------------------------
* Simple function to check whether the specified string can be considered as a boolean value
*/

View File

@ -208,6 +208,23 @@ CSStr ToStringF(CSStr str, ...)
return b.Get< SQChar >();
}
// ------------------------------------------------------------------------------------------------
SQRESULT SqThrowErrorF(HSQUIRRELVM vm, CCStr str, ...)
{
// Prepare the arguments list
va_list args;
va_start(args, str);
// Write the requested contents
if (std::vsnprintf(g_Buffer, sizeof(g_Buffer), str, args) < 0)
{
return sq_throwerror(vm, _SC("Formatting error occurred while throwing a script error"));
}
// Finalize the argument list
va_end(args);
// Throw the resulted string
return sq_throwerror(vm, g_Buffer);
}
// ------------------------------------------------------------------------------------------------
bool SToB(CSStr str)
{