Stopping a running script
MickeyDelp opened this issue · 3 comments
When embedding tinyscript in a larger application, a way is needed to stop a running script. A user could have a script that contains a while(1). My suggestion is to declare an external function, perhaps called TinyScript_Stop, that returns a zero to keep going or a non zero to stop.
Putting the call at the beginning of ParseStmt works well. Like this:
if (TinyScript_Stop())
{
return TS_ERR_STOPPED;
}
If you agree, I can do a PR, but I am open to other implementations too.
That sounds like a good idea, although I'd like to have it #ifdef'd -- maybe have a default definition like:
#ifndef TinyScript_Stop
#define TinyScript_Stop() (0)
#endif
The preprocessor does not know if the external function exists, That is not known until link time. I think we need to just explain it in the header. Something like this:
// if an external function is provided, comment out the define, and uncomment the function declaration
#define TinyScript_Stop() 0
//extern int TinyScript_Stop();
Fixed, thanks for the pull request!