lua-users home
lua-l archive

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


..
On Fri, May 3, 2013 at 12:24 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
2013/5/3 David Given <dg@cowlark.com>:

> local functable = {
>         ["func1"] = func1,
>         ["func2"] = func2,
>         ["func3"] = func3,
> }

Or

local functable = {
         func1 = func1,
         func2 = func2,
         func3 = func3,
 }


Or if your functions are small enough, even:

local functable = {
         func1 = function(arg1, arg2) return arg1 + arg2 end,
         func2 = function(arg1, arg2) return arg1 - arg2 end,
         func3 = function(arg1, arg2) return arg2 - arg1 end,
 }

The only difference between a local and a global function is that a global function can be found in _G. Whether it got there by writing "function myfunc(...)" or by "_G.myfunc = myfunc" or "function _G.myfunc(...)" or "_G.myfunc = function(...)" makes no difference.

--
Sent from my Game Boy.