mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add argument check library
This commit is contained in:
parent
2ddca1e9d1
commit
8d1afaa9e4
33
checkarg.lua
Normal file
33
checkarg.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
local function do_check(x, expected_type)
|
||||
if (type(x) ~= expected_type) then
|
||||
error(expected_type .. " expected, got " .. type(x))
|
||||
end
|
||||
end
|
||||
|
||||
function checknumber(n)
|
||||
do_check(n, "number")
|
||||
end
|
||||
|
||||
function checkstring(n)
|
||||
do_check(n, "string")
|
||||
end
|
||||
|
||||
function checknil(n)
|
||||
do_check(n, "nil")
|
||||
end
|
||||
|
||||
function checkbool(n)
|
||||
do_check(n, "boolean")
|
||||
end
|
||||
|
||||
function checkuserdata(n)
|
||||
do_check(n, "userdata")
|
||||
end
|
||||
|
||||
function checkfunc(n)
|
||||
do_check(n, "function")
|
||||
end
|
||||
|
||||
function checktable(n)
|
||||
do_check(n, "table")
|
||||
end
|
Loading…
Reference in New Issue
Block a user