From 1c071214b577c1f5d6cc8591b6b35f8dfad3635c Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Mon, 13 Apr 2020 02:16:31 -0400 Subject: [PATCH] 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? --- util/lua-ext.lua | 12 ------------ util/pokemon.lua | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/util/lua-ext.lua b/util/lua-ext.lua index e60297ba..8668a4ca 100644 --- a/util/lua-ext.lua +++ b/util/lua-ext.lua @@ -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 diff --git a/util/pokemon.lua b/util/pokemon.lua index d3091930..644412c4 100644 --- a/util/pokemon.lua +++ b/util/pokemon.lua @@ -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