Skip to content

Version 1.1.0 (Checking the number of function arguments)

Compare
Choose a tag to compare
@mtrempoltsev mtrempoltsev released this 30 May 10:26
· 112 commits to master since this release

Now the library can determine that the number of arguments does not match.

Example:

exam.lua

local checks = require('checks')

local function f1(x, y)
    checks('number')
end

local function f2(x)
    checks('number', 'number')
end

local function f3(x)
    checks('number')
end

f1(1) -- exam.lua:4:  too many arguments to function f1

--f2(1) -- exam.lua:8:  too few arguments to function f2

--f3('1') -- exam.lua:12:  bad argument #1 to f3 (number expected, got string)

f3(1, 2) -- ok :(

f3(1) -- ok

--f1(1, 2)

f2(1, 2)

Limitations

From the begining of function to the checks you must not declare a local variable.

function foo(x)
    local y = 5 -- WRONG!!!
    checks('number')
end