lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Not sure if this is where I should post, but...

I've been teaching myself some of the Lua API, but the documentation is
very confusing. What I'm trying to do is make a system such that a Lua
script is parsed one instruction at a time, returning information to the
function doing the processing.

For example:
int hypothetical_function ()
{
  ...

  while ( !stop )
  {
    result = run_next_instruction ( script );
    switch (result)
    {
      case DO_SOMETHING:
        ... // DO_SOMETHING would be returned if the Lua Script called,
say, the function do_something() as the last instruction.
        break;
      case DO_SOMETHING_ELSE:
        ... // DO_SOMETHING_ELSE would be returned if the Lua Script
called, say, the function do_something_else() as the last instruction.
        break;
      case STOP_PARSING:
        stop = TRUE;
        break;
    }
    ...
  }
}

Now, I've managed to get the thing going an instruction at a time using
Lua debug hooks set to 1 instruction, pointing to a function that make
it yield.

The bit that's baffling me is how to make the 'yield' return a value. I
thought about maybe making do_something() and do_something_else()
setting a global which is then checked directly after the script yields
(for example do_something() sets the global return_value to something
which is picked up). But I have no idea how to go about this.

Can anyone help (or offer suggestions)?