lua-users home
lua-l archive

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

> From: Christophe Gimenez
> Sent: Tuesday, March 28, 2000 1:27 AM
> Time-based callbacks:  on_Time(who)
> This allows you to write loops.  Each iteration of the loop is another
> callback.  This keeps the other scripts from hanging while the loop is
> going
> on.
> --> Can you explain further please ? What do you mean by "Each
> iteration of
> the loop is another
> callback."

If you want to write a loop like this:

while condition do

Then you can implement it as a timer callback like this:

function on_Timer()
   if condition then
       SetTimer( interval, on_Timer )


Each iteration of the original "while" loop is replaced by a callback to
on_Timer.  My example assumes that SetTimer causes only one callback, so you
have to call SetTimer once for each iteration.  It's not hard to implement
this for other timer semantics though.

> Input callbacks: on_KeyDown, on_MouseMove, etc.
> --> Honnestly I would prefer to avoid handling direcly the input of the
> user... (not yet defined how the dialog will be handled)

This brings up a recurring issue with Lua development.  What's the best
place to draw the line between Lua and C code?  On the one hand, you want
the flexibility of Lua, on the other you want the speed and power of C.

I have found it helpful to start by writing low-level Lua interfaces, and
then supplement them with higher-level interfaces as need dictates.  This
way you always have maximum control and flexibility in Lua, and you only pay
for the power of C when you require it.

Regardless, I agree with you in this situation.  I ended up adding
higher-level APIs:

   on_PlaceAction( actor, to_place )
   on_ObjectAction( actor, to_object )

However, I kept the low-level mouse and key APIs and I sometimes use them
during testing and development.

> --> I've tried to find information about FSM but never found a document
> that was really easy to understand...

A few of the links on the first page looked helpful, perhaps they are new to