lua-users home
lua-l archive

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


Hi:

On Sat, Sep 28, 2013 at 2:55 PM, Jayanth Acharya <jayachar88@gmail.com> wrote:
> Thanks Matt. While I understand why your snippet works, I still don't
> understand why mine doesn't. Anyhow, I shall fall back to the FSM code in
> the Lua wiki link in my OP -- now that I understand it bit better, would
> still be a good thing to figure out the issue with my snippet.

If you 'unroll' the table building you can see it, the original snippet:

fsm = { s1 = { e1 = { 's2', a1}},
        s2 = { e2 = { 's3', a2}},
        s1 = { e2 = { 's1', nil}},
        s2 = { e3 = { 's4', a3}}
      }

Would be something like:
fsm={}
fsm[s1] = { e1 = { 's2', a1}},
fsm[s2] = { e2 = { 's3', a2}}
fsm[s1] = { e2 = { 's1', nil}}  <==== Overwriting previous value of fsm[s1],
fsm[s2] = { e3 = { 's4', a3}}

While the fixed ( reindented to better show the difference ) one:

 fsm = { s1 = { e1 = { 's2', a1},  e2 = { 's1', nil} },
            s2 = { e2 = { 's3', a2}, e3 = { 's4', a3}}
      }

would be something like:

fsm={}
fsm[s1] = { e1 = { 's2', a1}, e2 = { 's1', nil}}
fsm[s2]=  { e2 = { 's3', a2}, e3 = { 's4', a3}}

Regards.
 Francisco Olarte.