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

Squirrel does not report syntax errors.
Kelvin
#1 Posted : Monday, June 27, 2016 12:48:57 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
OK, so I have two apps using Squirrel. One is a console app I use for tutorials and code testing, and the other is XYG, which uses SDL2 for I/O. For the console app, it reports errors just fine, but XYG is not reporting them, except for when I call an embedded function with the wrong number/kind of parameters. Otherwise, it crashes silently.

They both use the same code for handling errors, both calling sqstd_seterrorhandlers() before calling sq_setprintfunc(), and both use the same function for printing output, which uses vprintf for printing to the console. The only difference there is that XYG also uses vfprintf to copy output to a log.txt file, and the function has a different name. Otherwise, they both have this same code:

Code:
vm = sq_open(1024);
sqstd_seterrorhandlers(vm);
sq_setprintfunc(vm, printfunc, printfunc);
sq_pushroottable(vm);


This is the print function for the console testbed:
Code:
void printfunc(HSQUIRRELVM v, const SQChar *s, ...){
    va_list arglist;
    va_start(arglist, s);
    vprintf(s, arglist);
    va_end(arglist);
};


This is for XYG:
Code:
void xyPrint(HSQUIRRELVM v, const SQChar *s, ...){
    va_list args;
    va_start(args, s);
    xyUpdateTime();
    fprintf(gvLog, ">::%i\'%i\"%i:%i\n", gvHours, gvMinutes, gvSeconds, gvTicks);
    vfprintf(gvLog, s, args);
    printf(">::%i\'%i\"%i:%i\n", gvHours, gvMinutes, gvSeconds, gvTicks);
    vprintf(s, args);
    printf("\n\n");
    fprintf(gvLog, "\n\n");
    va_end(args);
};


XYG does not print Squirrel errors to the console or log file. I can't find anything else that could possibly be affecting them. xyUpdateTime() just takes SDL ticks and converts them into a readable format. Like I said, it prints parameter errors, but if I do something like turn "local" into "loal", or use an operator that isn't supported by Squirrel, it just cuts off and does nothing. No errors are reported. Putting the same code in the testbed shows the errors correctly.

Does anyone have any idea what's wrong?
absence
#2 Posted : Tuesday, June 28, 2016 2:12:11 PM(UTC)
Rank: Advanced Member

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

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
Kelvin wrote:

The only difference there is that XYG also uses vfprintf to copy output to a log.txt file, and the function has a different name. Otherwise, they both have this same code:

Code:
vm = sq_open(1024);
sqstd_seterrorhandlers(vm);
sq_setprintfunc(vm, printfunc, printfunc);
sq_pushroottable(vm);




Note that what you describe relates to compiler errors, not runtime errors.
You made sure gvLog is valid and open at compile time?
You did setprintfunc properly for XYG? (sq_setprintfunc(vm,xyPrint, xyPrint))

you can, however, also try to utilize sq_setcompilererrorhandler and do things separately on your own
Kelvin
#3 Posted : Tuesday, June 28, 2016 11:02:38 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
gvLog is the first thing opened in the program, and setprintfunc is used the same way in both programs.

And I looked up the function you mentioned, and it said to put this in my code:
Code:
typedef void (*SQCOMPILERERROR)(HSQUIRRELVM /*v*/,const SQChar * /*desc*/,const SQChar *
/*source*/,SQInteger /*line*/,SQInteger /*column*/);

This doesn't make any sense to me, though. What does this mean? Why are all the variables commented out? Where is the body to the function?
absence
#4 Posted : Saturday, July 2, 2016 6:13:23 PM(UTC)
Rank: Advanced Member

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

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
Kelvin wrote:
gvLog is the first thing opened in the program, and setprintfunc is used the same way in both programs.

Well, the same way, but did you make sure you do not set the console printfunc by mystake for XYG?
(Then it _should_ actually do, I think, because by using sqstd_seterrorhandlers the compiler uses its default handler which in turn uses the default error-printfunc you then set by setprintfunc)

Quote:

And I looked up the function you mentioned, and it said to put this in my code:
Code:
typedef void (*SQCOMPILERERROR)(HSQUIRRELVM /*v*/,const SQChar * /*desc*/,const SQChar *
/*source*/,SQInteger /*line*/,SQInteger /*column*/);

This doesn't make any sense to me, though. What does this mean? Why are all the variables commented out? Where is the body to the function?


Uh oh... this is a function prototype. You have to write a function matching that prototype to be able to pass it to squirrel (it's pretty much the same like with setprintfunc, just the prototype differs and has different parameters to use. So you'll find another typedef for a printfunc, too, when you look up sq_setprintfunc, maybe that will make it more clear).
The variables are commented out because a typedef prototype must not have variable names, it declares the variable types and order ONLY. The comments are there just to indicate the USE of the respective parameter to the reader.


Kelvin
#5 Posted : Tuesday, July 5, 2016 2:28:54 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
So, I should make a void-type function with those parameter types in that order? Then, I guess just have the function call xyPrint using the arguments in the message?
absence
#6 Posted : Friday, July 8, 2016 12:39:07 PM(UTC)
Rank: Advanced Member

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

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
you could give it a try. This is the standard handler that I think is active in your setup (set by sqstd_seterrorhandlers):


Code:

void _sqstd_compiler_error(HSQUIRRELVM v,const SQChar *sErr,const SQChar *sSource,SQInteger line,SQInteger column)
{
    SQPRINTFUNCTION pf = sq_geterrorfunc(v);
    if(pf) {
        pf(v,_SC("%s line = (%d) column = (%d) : error %s\n"),sSource,line,column,sErr);
    }
}

set by

Code:

void sqstd_seterrorhandlers(HSQUIRRELVM v)
{
    sq_setcompilererrorhandler(v,_sqstd_compiler_error);
    sq_newclosure(v,_sqstd_aux_printerror,0);
    sq_seterrorhandler(v);
}


where sqstd_auc_printerror utilizes the second print function set by sq_setprintfunc:

Code:


static SQInteger _sqstd_aux_printerror(HSQUIRRELVM v)
{
    SQPRINTFUNCTION pf = sq_geterrorfunc(v);
    if(pf) {
        const SQChar *sErr = 0;
        if(sq_gettop(v)>=1) {
            if(SQ_SUCCEEDED(sq_getstring(v,2,&sErr)))   {
                pf(v,_SC("\nAN ERROR HAS OCCURED [%s]\n"),sErr);
            }
            else{
                pf(v,_SC("\nAN ERROR HAS OCCURED [unknown]\n"));
            }
            sqstd_printcallstack(v);
        }
    }
    return 0;
}


so i again have to ask if you PROPERLY set up your sq_printfunc calls for your XYG after calling sqstd_seterrorhandlers(vm). Another explanation would be having additional calls to sqstd_seterrorhandlers(vm) or sq_setprintfunc happening elsewhere in the code?

Kelvin
#7 Posted : Saturday, July 9, 2016 8:51:48 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
This is what I have:

Code:
sq_setcompilererrorhandler(gvSquirrel, xyError);
sq_newclosure(gvSquirrel, xyPrint, 0);
sq_seterrorhandler(gvSquirrel);
sqstd_seterrorhandlers(gvSquirrel);
sq_seterrorhandler(gvSquirrel);
sq_setprintfunc(gvSquirrel, xyPrint, xyPrint);
sq_pushroottable(gvSquirrel);


Same as with the test app, just different function names.

It gave me this error:
Code:
error C2664: 'sq_newclosure' : cannot convert parameter 2 from 'void (__cdecl *)(HSQUIRRELVM,const SQChar *,...)' to 'SQFUNCTION'


Also, I noticed _SC() isn't in the documentation. What is that?
Kelvin
#8 Posted : Saturday, July 9, 2016 11:40:23 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
I just noticed in my last post that I accidentally put sq_seterrorhandler() in twice. I removed one of them, and still get the same problem. It also doesn't seem to have anything to do with SDL, since other messages using printf() go through just fine. It's only the compile errors that don't get printed.
Kelvin
#9 Posted : Sunday, July 10, 2016 11:18:32 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
And I just tried using the code from the sq.c example that Squirrel comes with, though the only difference there was some things were done in a different order. It still doesn't work. I can't find any other difference in the print code anywhere. I even tried copying my print function into a separate error function just to see if using different functions would somehow solve it, and it doesn't. I'm literally pulling hair out over this. I can't think of any other reason why Squirrel is deciding not to print compile errors.
fagiano
#10 Posted : Monday, July 11, 2016 6:52:08 AM(UTC)
Rank: Advanced Member

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

Thanks: 0 times
Was thanked: 78 time(s) in 60 post(s)
why do you call sqstd_seterrorhandlers if you are trying to set your own error function?. sqstd_seterrorhandlers overrides your function.

Alberto
Follow me on Twitter @squirrellang
absence
#11 Posted : Monday, July 11, 2016 1:22:21 PM(UTC)
Rank: Advanced Member

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

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
[quote=Kelvin]This is what I have:

Code:
sq_setcompilererrorhandler(gvSquirrel, xyError);
sq_newclosure(gvSquirrel, xyPrint, 0);
sq_seterrorhandler(gvSquirrel);
sqstd_seterrorhandlers(gvSquirrel);
sq_seterrorhandler(gvSquirrel);
sq_setprintfunc(gvSquirrel, xyPrint, xyPrint);
sq_pushroottable(gvSquirrel);


ooooh yes, Alberto is right. You set the error handler, and THEN you call sqstd_seterrorhandlers - which will overwrite it.
Do it the other way around. Or leave out sqstd_seterrorhandlers, as you are setting your own printfuncs anyways. That's exactly what sqstd_setterrorhandlers does:
- set a compiler error handler
- set the runtime error handler
( BTW: I posted the code of sqstd_seterrorhandlers above )

BUT, AGAIN: This code looks totally different to the one you initially had. Do you maybe have TWO LOCATIONS WHERE YOU SET THE PRINTFUNCS???
I have the notion you start mixing things up.
I recommend going back, remove all your code about printfuncs and errorhandler. Literally everything. Then choose ONE location, best where you create your vm - and afterwards you do call:

sqstd_seterrorhandlers(vm) ; //the default error handler will use the default print funcs...
sqstd_setprintfuncs(normal,errorfunc) ; //which you set here

and then you should be doing fine.
If this does not work, search SQRat for sq_seterror... and sq_setprint..., note WHEN it does those and make your code execute above two lines LATER in program execution.


Kelvin
#12 Posted : Thursday, July 14, 2016 12:57:34 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 3/26/2015(UTC)
Posts: 46
Man
Location: VA

Thanks: 2 times
Was thanked: 0 time(s) in 0 post(s)
Quote:
BUT, AGAIN: This code looks totally different to the one you initially had. Do you maybe have TWO LOCATIONS WHERE YOU SET THE PRINTFUNCS???

See my earlier post.

But a friend found the problem for me. Turns out, the error handlers are fine; I just forgot to turn them on when telling it to run a .nut file. >.-.< I feel so stupid now.
Users browsing this topic
Guest
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.246 seconds.