Use utf8.char, tup supports lua 5.3 after all

Did it gain support in a later version? Or, was I imagining it only
supporting 5.1 from the start?
This commit is contained in:
Christopher Monsanto
2020-04-13 02:16:31 -04:00
parent df7a034099
commit 1c071214b5
2 changed files with 1 additions and 13 deletions

View File

@@ -19,15 +19,3 @@ function astable(table)
return {}
end
end
-- Lua 5.1, which ships with Tup, does not have a way of creating a string from
-- a unicode codepoint...
--
-- https://stackoverflow.com/a/7799843
function unichr(ord)
if ord == nil then return nil end
if ord < 32 then return string.format('\\x%02x', ord) end
if ord < 126 then return string.char(ord) end
if ord < 65539 then return string.format("\\u%04x", ord) end
if ord < 1114111 then return string.format("\\u%08x", ord) end
end

View File

@@ -2,7 +2,7 @@
function decodeFS(filename)
return filename:gsub('_(%x%x%x%x)',
function(hex)
return unichr(tonumber(hex, 16))
return utf8.char(tonumber(hex, 16))
end)
end