[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: David Given <dg@...>
- Date: Tue, 12 Jan 2010 10:56:27 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/01/10 10:50, sean farrow wrote:
[...]
> Now if I know the value of the number of the function in the table I wish
> to call (x) how can I call this without iterating through the
> table-essentially is there a way of finding a value in a table given it's
> key?
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"))
- --
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "Sufficiently advanced incompetence is indistinguishable from
│ malice." -- Vernon Schryver
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAktMVVYACgkQf9E0noFvlzgyuQCfeToqGEGqnglyd4N56ewjEHGs
hmgAoIRGb6U27xb/9l8/DiHR2GXXzs7M
=XLyy
-----END PGP SIGNATURE-----