lua-users home
lua-l archive

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


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.


On Sat, Sep 28, 2013 at 5:50 PM, D. Matt Placek <atomicsuntan@gmail.com> wrote:

On Sat, Sep 28, 2013 at 2:38 AM, Jayanth Acharya <jayachar88@gmail.com> wrote:
fsm = { s1 = { e1 = { 's2', a1}},
        s2 = { e2 = { 's3', a2}},
        s1 = { e2 = { 's1', nil}},
        s2 = { e3 = { 's4', a3}}
      }

Try instead:

 fsm = { s1 = { e1 = { 's2', a1},
                      e2 = { 's1', nil} },
            s2 = { e2 = { 's3', a2},
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} !