[Solved] Stop a running picoc script (thanks a1ex)

Started by wolf, February 13, 2013, 06:19:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

wolf

I tried to detect a key while a script is running...

if (script_state != SCRIPT_IDLE)
    {
        if (event->param == BGMT_PRESS_UP)
        {
         ??????
         ??????
        }
    }


but could not find the comand or function to stop a script. Whatever I tried results in no effect or in hanging.

Is there a way to stop a task. Sorry if this question is stupid.
task_create("run_script", 0x1c, 0x4000, run_script, 0);

a1ex

That's not very easy. I think you can find picoc's main loop (probably around parse.c:838, not sure) and add something like this: if (stop_requested) ProgramFail(blahblah). In the GUI event handler, you make stop_requested = true and the script should stop at next instruction.

wolf

I can't figure out where to define the variable stop_requeseted

if I define it in picoc.h:

int stop_requested;

and add to parse.c
do {
        Ok = ParseStatement(&Parser, TRUE);
        if (stop_requested)
        ProgramFail(&Parser, "please stop");

    } while (Ok == ParseResultOk);


and in src/picoc.c
if (event->param == BGMT_PRESS_UP)
        {
            stop_requested=1;
            return 0;
        }



nothing happes.
but when I for test reasons add
stop_requested=1;
to parse.c it will stop or not start.

So I guess with my little C understanding the variable stop_requested isn't right defined.


a1ex

Added to repo; that loop wasn't quite the right place for stopping the script.

I've tested it with the image processing example from http://www.magiclantern.fm/forum/index.php?topic=4571 .

wolf