From 8d1afaa9e4ce3bb4199fd232d3fab2bbf344e743 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Mon, 23 Oct 2017 15:09:02 +0800 Subject: [PATCH] Add argument check library --- checkarg.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 checkarg.lua diff --git a/checkarg.lua b/checkarg.lua new file mode 100644 index 0000000..1c57c98 --- /dev/null +++ b/checkarg.lua @@ -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