From 5328b62221a3839dca117d71a4703f3ad719c9ce Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 22 Feb 2024 00:23:32 -0600 Subject: Add global and types libraries --- types.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 types.lua (limited to 'types.lua') diff --git a/types.lua b/types.lua new file mode 100644 index 0000000..dd105cf --- /dev/null +++ b/types.lua @@ -0,0 +1,27 @@ +--- lam.types + +local types = {} + +types.luatype = type + +function types.lamtype (x) + if types.luatype(x) == "string" then + return "Symbol" + elseif types.luatype(x) == "number" then + return "Number" + elseif getmetatable(x) and getmetatable(x).__type then + return getmetatable(x).__type + elseif types.luatype(x) == "table" then + return "List" + else + return types.luatype(x) + end +end + +types["number?"] = function (x) return types.lamtype(x) == "Number" end +types["symbol?"] = function (x) return types.lamtype(x) == "Symbol" end +types["list?"] = function (x) return types.lamtype(x) == "List" end +types["null?"] = function (x) return x == {} end + +--- +return types -- cgit 1.4.1-21-gabe81