YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

sq_throw variable arguments
belbardonisakel
#1 Posted : Tuesday, December 22, 2015 9:07:28 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/28/2015(UTC)
Posts: 9
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello Squirrel developer

i would like to change the signature of the function sq_throwerror like squilu did in
https://github.com/mingo...uiLu/squirrel/sqapi.cpp line 1348

Changed Code is:
SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *fmt, ...);

SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *fmt, ...)
{
SQChar err[256];
va_list vl;
va_start(vl, fmt);
scvsnprintf(err, sizeof(err), fmt, vl);
va_end(vl);
v->_lasterror=SQString::Create(_ss(v),err);
return SQ_ERROR;
}

Actual implementation is (sqapi.cpp line 1035):

SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err)
{
v->_lasterror=SQString::Create(_ss(v),err);
return SQ_ERROR;
}


Then it will gets much easier to give more precise error messages including state variables:

e.g.:
return sq_throwerror(v, "cannot open %s: %s", path, strerror (errno))

The Code seems to be under the original license - so should not a problem to include in main line.
https://github.com/mingo...master/SquiLu/COPYRIGHT

Tx for your support
Regards Heiko
absence
#2 Posted : Wednesday, December 23, 2015 4:45:50 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 107
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
My opinion:
I'd rather not change the API here, as sq_throwerror also is used internally,so changing the API would simply degrade performance a bit.
If you need it, just wrap it yourself in a new function you use - it's trivial.

However, Alberto needs to decide - it probably won't break things (and VA is used for printfunc anyways, no impact on libs involved).
belbardonisakel
#3 Posted : Friday, December 25, 2015 11:57:31 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/28/2015(UTC)
Posts: 9
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello absence

thank you for forewarding this issue.

I know this is a trivial point, but this is exactly the reason why i post it in the review board - should not be a big deal to change it. It would be definitely helpful for everybody who writes squirrel extensions if you put it in the next version of the interpreter.

>>... so changing the API would simply degrade performance a bit.
You're right, but the "sq_throw" function will normally only be called if an irregular exception occurs - so in 99% of the cases where your *.nut program works well it has no influence on the performance.
Only if your program crashes it will be slow down - but in this case the decrease of time is for sake of a clear error message.

Regards
fagiano
#4 Posted : Friday, December 25, 2015 5:07:37 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 1,054

Thanks: 0 times
Was thanked: 77 time(s) in 59 post(s)
If this is added should be sqstd_throwerror() as an helper function. I'd rather keep the core api as simple as possible, there are people running squirrel with 20Kb or RAM and "SQChar terr[256]" is not acceptable as a general purpose solution.

Alberto
Follow me on Twitter @squirrellang
belbardonisakel
#5 Posted : Friday, December 25, 2015 6:02:41 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/28/2015(UTC)
Posts: 9
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hello Alberto

to add sqstd_throwerror(HSQUIRRELVM v,const SQChar *fmt, ...) as a helper function sounds good to me :-)

Tx Heiko
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.133 seconds.