Function which returns how many parameters are in a function

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
image

is there any work around/replacement for this function natively found in lua?

1 Like

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.