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]
- Subject: Re: calling a function who's name is stored in a lua table
- From: Nevin Flanagan <Alestane@...>
- Date: 2010年1月12日 08:21:32 -0500
> 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).