2.7. Compiling a script
You can compile a Quirrel script with the function sq_compile.:
SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,
const SQChar *sourcename,SQBool raiseerror);
In order to compile a script is necessary for the host application to implement a reader function (SQLEXREADFUNC); this function is used to feed the compiler with the script data. The function is called every time the compiler needs a character; It has to return a character code if succeed or 0 if the source is finished.
If sq_compile succeeds, the compiled script will be pushed as Quirrel function in the stack.
When the compiler fails for a syntax error it will try to call the ‘compiler error handler’; this function must be declared as follow:
typedef void (*SQCOMPILERERROR)(HSQUIRRELVM /*v*/,const SQChar * /*desc*/,const SQChar * /*source*/,
SQInteger /*line*/,SQInteger /*column*/);
and can be set with the following API call:
void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);