In JavaScript, you can ask a function object how many arguments does it expect. Is the same thing possible in Lua?
Asked
Active
Viewed 64 times
2
-
For a function implemented in Lua, you can also get a "signature" of sorts. See my [answer](http://stackoverflow.com/a/24216007/2226988) to [Is there a way to determine the signature of a Lua function?](http://stackoverflow.com/q/142417/2226988). – Tom Blodget Jul 10 '14 at 02:39
2 Answers
4
If you're using Lua 5.2, you can use debug.getinfo(f).nparams
.
(answer edited in light of Luiz's answer, previous answer was correct only for Lua 5.1)

Mud
- 28,277
- 11
- 59
- 92
-
You should also add that __ANY__ number of arguments can be passed to a function in lua. – hjpotter92 Jul 09 '14 at 18:05