diff options
author | Case Duckworth | 2024-02-22 00:23:32 -0600 |
---|---|---|
committer | Case Duckworth | 2024-02-22 00:23:32 -0600 |
commit | 5328b62221a3839dca117d71a4703f3ad719c9ce (patch) | |
tree | 7212235f569e765d3a4ebed0e8d21b64d905bf3a /types.lua | |
parent | Remove spurious require (diff) | |
download | lam-5328b62221a3839dca117d71a4703f3ad719c9ce.tar.gz lam-5328b62221a3839dca117d71a4703f3ad719c9ce.zip |
Add global and types libraries
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 | ||