diff options
author | Case Duckworth | 2024-02-21 09:28:49 -0600 |
---|---|---|
committer | Case Duckworth | 2024-02-21 09:28:49 -0600 |
commit | 70ec5254814f9531e5ca2024465d0e01130306b7 (patch) | |
tree | 45a4d49115eca436a8467ce4cebfc8cee1f6f9c6 /types.lua | |
download | lam-70ec5254814f9531e5ca2024465d0e01130306b7.tar.gz lam-70ec5254814f9531e5ca2024465d0e01130306b7.zip |
Initial commit
Diffstat (limited to 'types.lua')
-rw-r--r-- | types.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/types.lua b/types.lua new file mode 100644 index 0000000..042edce --- /dev/null +++ b/types.lua | |||
@@ -0,0 +1,37 @@ | |||
1 | --- lam.types | ||
2 | |||
3 | local types = {} | ||
4 | |||
5 | function types.Type(x) | ||
6 | if type(x) == "string" then | ||
7 | -- Symbols are Lua strings | ||
8 | return "Symbol" | ||
9 | elseif type(x) == "number" then | ||
10 | -- Numbers are Lua numbers | ||
11 | return "Number" | ||
12 | elseif x.__type then | ||
13 | return x.__type | ||
14 | elseif type(x) == "table" then | ||
15 | -- Lists are Lua tables (non-adorned) | ||
16 | return "List" | ||
17 | else | ||
18 | return type(x) | ||
19 | end | ||
20 | end | ||
21 | |||
22 | types.Object = { __type = "Object" } | ||
23 | function types.Object:new(o) | ||
24 | o = o or {} | ||
25 | setmetatable(o, self) | ||
26 | self.__index = self | ||
27 | return o | ||
28 | end | ||
29 | |||
30 | --- Boxed types | ||
31 | |||
32 | -- Strings | ||
33 | |||
34 | -- Lists | ||
35 | |||
36 | --- | ||
37 | return types | ||