lua-users home
lua-l archive

Re: calling a function who's name is stored in a lua table

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


> All globals, including functions, are (usually) stored in a special
> table called _G. So all you need to do is:
> 
> function callfunction(n, ...)
> local name = AtcActions(n)
> local f = _G[name]
> return f(...)
> end
> 
> e.g.:
> print(callfunction("2", "word"))
It's also perfectly functional to write
_G[AtcActions(n)](...)
(although not always easy to read).

AltStyle によって変換されたページ (->オリジナル) /