diff options
Diffstat (limited to 'types.lua')
-rw-r--r-- | types.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/types.lua b/types.lua new file mode 100644 index 0000000..dd105cf --- /dev/null +++ b/types.lua | |||
@@ -0,0 +1,27 @@ | |||
1 | --- lam.types | ||
2 | |||
3 | local types = {} | ||
4 | |||
5 | types.luatype = type | ||
6 | |||
7 | function types.lamtype (x) | ||
8 | if types.luatype(x) == "string" then | ||
9 | return "Symbol" | ||
10 | elseif types.luatype(x) == "number" then | ||
11 | return "Number" | ||
12 | elseif getmetatable(x) and getmetatable(x).__type then | ||
13 | return getmetatable(x).__type | ||
14 | elseif types.luatype(x) == "table" then | ||
15 | return "List" | ||
16 | else | ||
17 | return types.luatype(x) | ||
18 | end | ||
19 | end | ||
20 | |||
21 | types["number?"] = function (x) return types.lamtype(x) == "Number" end | ||
22 | types["symbol?"] = function (x) return types.lamtype(x) == "Symbol" end | ||
23 | types["list?"] = function (x) return types.lamtype(x) == "List" end | ||
24 | types["null?"] = function (x) return x == {} end | ||
25 | |||
26 | --- | ||
27 | return types | ||