This is possible only through the debug library, but it is possible.
print(debug.getinfo(test, 'u').nparams) -- number of args
print(debug.getinfo(test, 'u').isvararg) -- can take variable number of args?
Please see here and here for more information.
Edit: Just in case you wanted to play with some black magic...
debug.setmetatable(function() end, {
__len = function(self)
-- TODO: handle isvararg in some way
return debug.getinfo(self, 'u').nparams
end
})
This will make it possible to use the # length operator on functions and provide a JavaScript-esque feel. Note however that this will likely only work in Lua 5.2 and above.