Skip to content

Function Length #820

@hazzard993

Description

@hazzard993

In JS a function's length is the number of parameters a function takes excluding the rest parameter.

function x(a, b, c) {}
x.length; // 3

function y(...rest) {}
y.length; // 0

Same rules apply to Lua's nparams.

function x(a, b, c) end
debug.getinfo(x).nparams -- 3

function y(...) end
debug.getinfo(y).nparams -- 0

debug.getinfo(a).nparams seems to be usable in all supported Lua environments except for 5.1.

Lua 5.3 ✔
Lua 5.2 ✔
LuaJIT ✔
Lua 5.1 ❌

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions