about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--type.lua21
1 files changed, 14 insertions, 7 deletions
diff --git a/type.lua b/type.lua index 83b29f2..baf9a67 100644 --- a/type.lua +++ b/type.lua
@@ -31,20 +31,27 @@ m.character_names = {
31} 31}
32 32
33function m.character (x) 33function m.character (x)
34 local s = tostring(x) 34 local char, code
35 local uc = utf8.codepoint(s) 35 if m.luatype(x) == "number" then
36 code = x
37 char = utf8_char(x)
38 elseif m.luatype(x) == "string" then
39 code = utf8_codepoint(x)
40 char = utf8_char(code)
41 end
36 local t = { 42 local t = {
37 v = utf8.char(uc), 43 char = char,
38 u = uc, 44 code = code,
39 } 45 }
40 local mt = { 46 local mt = {
41 __type = "char", -- scheme name 47 __type = "char", -- scheme name
42 -- compare using codepoints since they're just numbers 48 -- compare using codepoints since they're just numbers
43 __eq = function (a, b) return a.u == b.u end, 49 __eq = function (a, b) return a.code == b.code end,
44 __lt = function (a, b) return a.u < b.u end, 50 -- comparing codepoints is probably not the *best* idea
51 __lt = function (a, b) return a.code < b.code end,
45 __tostring = 52 __tostring =
46 function (self) 53 function (self)
47 local v = self.v 54 local v = self.char
48 if m.character_names[v] then 55 if m.character_names[v] then
49 v = m.character_names[v] 56 v = m.character_names[v]
50 end 57 end