Having a slow day... I was trying to understanding the FSM implementation described here:
http://lua-users.org/wiki/FiniteStateMachine
And thought of trying this alternative way, to see if I could use the 2-d array
snippet:
-- current-state -> { event --> { new-state, action-function }}
fsm = { s1 = { e1 = { 's2', a1}},
s2 = { e2 = { 's3', a2}},
s1 = { e2 = { 's1', nil}},
s2 = { e3 = { 's4', a3}}
}
print(fsm['s1'])
print(fsm['s1']['e1'])
gives the output:
>lua -e "io.stdout:setvbuf 'no'" "2darr.lua"
table: 003EB3D8
nil
>Exit code: 0
I was wondering, why the second print() results in nil ? I was expecting a table, that contains {'s2', a1} !