I’m trying to make a function that checks how many parameters are within a function. I know it exists in vanilla lua
function parameters(fn)
local info = debug.getinfo(fn)
return info.nparams
end
function foo(x,y) end
print(parameters(foo)) -- 2 parameters
function bar(x,y,z,a,b) end
print(parameters(foo)) -- 5 parameters
although I dont see the getinfo function in the library
is there any work around/replacement for this function natively found in lua?
The "a" specifier of the s argument (as specified in the link above) of the debug.info function would be an alternative in Luau.
function foo(x, y, z) end
print(debug.info(foo, "a")) -- 3 false
debug.info in Luau is basically debug.getinfo in vanilla Lua with the main difference being the interface. I presume the Luau team wasn’t satisfied with the interface of debug.getinfo so they decided to revamp them.