lua-users home
lua-l archive

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


Hello folks,

I'm trying to implement an FSM in Lua to model the state of a wireless router. The system is running OpenWRT, so using lua seems to be a reasonable choice.
Since I'm new to lua (I actually looked a lua yeasterday for the first time), I've some questions :-)

The FSM I'm trying build is splitted into two files:
-> One is used for defining the FSM. The definition itself is one big lua table. I've come up with this: http://pastebin.com/ypUuUmpJ
-> The other file implements a set_signal(signal, value) function (implementation outstanding).

Since the definition of the FSM should look well ("DSL-stylish"), this separation seem to be a valid choice.

However, I'm stucked with the set_signal(signal, value) function. The function should:
-> Increment counters (if defined for a given signal)
-> Iterate through all transitions, executing each guard.
-> If one guard evaluates to true:
-> Execute "onExit" using a system shell
-> Set the next state
-> Reset counters 
-> Execute "do" using a system shell
-> Execute "onEntry" using a system shell

I'm still looking for a way to evaluate the guards: How can I execute these strings having all signals available?

Another issue is IPC (inter process communication). The FSM is running in all time in its own process. If an event occurs (internet is available - for example) a seperate process (ppp's ip_up-script or whatever) must use ipc to trigger set_signal. 
What's the best way for ipc in your opionion? In theory (posix)-message queues should to the job, since queuing all events in the order they appear seem to be a logical, but their interface is rather complicated.

Thanks in advance,
Keep smiling
yanosz