lua-users home
lua-l archive

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


Hi all,

Our team is learning the subtleties of LUA and we are on a small newbies debate.

We are wondering what would be cheaper between calling a function from a table lookup or a string matching function.

Basically we have a Table that stores the name of the function. When a state machine runs and returns the name of the function we have the option to do this:

local actions = { pAuthRequest =  function ()
                                         print("Auth request coming!")
                                      end,
                      ClientSend =  function ()
                                       master:send(auth_string)
                                    end,
                      pCommandReply =  function ()
                                          print("Woohooo")
                                       end,
                      pWaiting = function ()
                                    print("Waiting for more")
                                 end,
                   }

local action = "">         action()

Or this instead:

function actions(action)
    if action ="" then
       print("Auth request coming!")
    end
<snip>


actions(a.action)

Hope the description above is clear enough so that you guys can shed some light on this.

Thanks in advance!