lua-users home
lua-l archive

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


Hey all:

I've implemented a simple slideshow engine in C and exposed control through
Lua.  So, C is "in charge", but the slideshow is described in Lua.  Now, I
want to let the user abort the rest of the slideshow via a keypress from the
C side, but I'm not sure how to best handle this.

A script essentially looks like this:

function Slideshow()
  Initialize()
  DoSlideshow()
  Cleanup()
  end

function DoSlideshow()
  ShowFrame()
  Wait(seconds)
  ShowFrame()
  Wait(seconds)
  ...
  end

I figured I could just return from DoSlideshow() upon a user signal and then
execute whatever cleanup code I need.  But I'm not sure how best to do this.

- Can I "inject" a return into the script via C? (dostring or something
similar)
- Or, do I have to abort my wait and then check a value like this:

  Wait(seconds)
  if (GetAbortFlag() == 1) then
    do return end
  ShowFrame()
  ...

That's a lot of code for the slideshow authors to have to include for each
frame of the show and seems a little messy.  (BTW: the slideshow is in a
coroutine that yields upon calling Wait() so the game can continue looping.)

Any ideas?