Fix warnings issued by `luacheck`.

This commit is contained in:
Diego Martínez 2017-02-11 01:56:54 -03:00
parent c667cd0de6
commit 122d1a83cc
5 changed files with 17 additions and 30 deletions

View File

@ -1,7 +1,6 @@
local strfind, strsub, strrep = string.find, string.sub, string.rep local strfind, strsub, strrep = string.find, string.sub, string.rep
local strmatch, strgsub = string.match, string.gsub local strmatch, strgsub = string.match, string.gsub
local floor = math.floor
local function split(str, sep) local function split(str, sep)
local pos, endp = 1, #str+1 local pos, endp = 1, #str+1
@ -103,6 +102,7 @@ local function parse_po(str)
return perror("malformed line") return perror("malformed line")
-- luacheck: ignore
until true end -- end for until true end -- end for
return texts return texts
@ -110,9 +110,6 @@ end
local M = { } local M = { }
local domains = { }
local dgettext_cache = { }
local dngettext_cache = { }
local langs local langs
local function detect_languages() local function detect_languages()
@ -166,8 +163,8 @@ end
-- Note that it assumes the C expression is valid to begin with. -- Note that it assumes the C expression is valid to begin with.
local function compile_plural_forms(str) local function compile_plural_forms(str)
local plural = strmatch(str, "plural=([^;]+);?$") local plural = strmatch(str, "plural=([^;]+);?$")
local function replace_ternary(str) local function replace_ternary(s)
local c, t, f = strmatch(str, "^(.-)%?(.-):(.*)") local c, t, f = strmatch(s, "^(.-)%?(.-):(.*)")
if c then if c then
return ("__if(" return ("__if("
..replace_ternary(c) ..replace_ternary(c)
@ -175,7 +172,7 @@ local function compile_plural_forms(str)
..","..replace_ternary(f) ..","..replace_ternary(f)
..")") ..")")
end end
return str return s
end end
plural = replace_ternary(plural) plural = replace_ternary(plural)
plural = strgsub(plural, "&&", " and ") plural = strgsub(plural, "&&", " and ")

View File

@ -86,7 +86,7 @@ end
local function catngettext(catalogs, msgid, msgid_plural, n) local function catngettext(catalogs, msgid, msgid_plural, n)
n = math.floor(n) n = math.floor(n)
for i, cat in ipairs(catalogs) do for _, cat in ipairs(catalogs) do
local msgstr = cat and cat[msgid] local msgstr = cat and cat[msgid]
if msgstr then if msgstr then
local index = cat.plural_index(n) local index = cat.plural_index(n)
@ -107,18 +107,18 @@ function intllib.make_gettext_pair(modname)
local localedir = minetest.get_modpath(modname).."/locale" local localedir = minetest.get_modpath(modname).."/locale"
local catalogs = gettext.load_catalogs(localedir) local catalogs = gettext.load_catalogs(localedir)
local getter = Getter(modname) local getter = Getter(modname)
local function gettext(msgid, ...) local function gettext_func(msgid, ...)
local msgstr = (catgettext(catalogs, msgid) local msgstr = (catgettext(catalogs, msgid)
or getter(msgid)) or getter(msgid))
return do_replacements(msgstr, ...) return do_replacements(msgstr, ...)
end end
local function ngettext(msgid, msgid_plural, n, ...) local function ngettext_func(msgid, msgid_plural, n, ...)
local msgstr = (catngettext(catalogs, msgid, msgid_plural, n) local msgstr = (catngettext(catalogs, msgid, msgid_plural, n)
or getter(msgid)) or getter(msgid))
return do_replacements(msgstr, ...) return do_replacements(msgstr, ...)
end end
gettext_getters[modname] = { gettext, ngettext } gettext_getters[modname] = { gettext_func, ngettext_func }
return gettext, ngettext return gettext_func, ngettext_func
end end

View File

@ -49,7 +49,7 @@ end
function intllib.load_strings(filename) function intllib.load_strings(filename)
local file, err = io.open(filename, "r") local file, err = io.open(filename, "r")
if not file then if not file then
return nil return nil, err
end end
local strings = {} local strings = {}
for line in file:lines() do for line in file:lines() do

View File

@ -123,7 +123,7 @@ table.sort(messages)
local last_msg local last_msg
for i, msg in ipairs(messages) do for _, msg in ipairs(messages) do
if msg ~= last_msg then if msg ~= last_msg then
printf("%s =\n", escape(msg)) printf("%s =\n", escape(msg))
end end

View File

@ -7,7 +7,7 @@ end
if basedir == "" then basedir = "./" end if basedir == "" then basedir = "./" end
-- Required by load_strings() -- Required by load_strings()
function string.trim(s) function string.trim(s) -- luacheck: ignore
return s:gsub("^%s*(.-)%s*$", "%1") return s:gsub("^%s*(.-)%s*$", "%1")
end end
@ -20,7 +20,7 @@ local function err(fmt, ...)
os.exit(1) os.exit(1)
end end
local template local output, outfile, template
local catalogs = { } local catalogs = { }
local function usage() local function usage()
@ -54,10 +54,7 @@ while i <= #arg do
if i > #arg then if i > #arg then
err("missing required argument to `%s'", a) err("missing required argument to `%s'", a)
end end
elseif (a == "-c") or (a == "--comment") then output = arg[i]
old_msg_mode = "c"
elseif (a == "-d") or (a == "--delete") then
old_msg_mode = "d"
elseif a:sub(1, 1) ~= "-" then elseif a:sub(1, 1) ~= "-" then
if not template then if not template then
template = a template = a
@ -81,27 +78,18 @@ if not f then
err("error opening template: %s", e) err("error opening template: %s", e)
end end
local function printf(fmt, ...)
outfile:write(fmt:format(...))
end
local escapes = { ["\n"] = "\\n", ["="] = "\\=", ["\\"] = "\\\\", } local escapes = { ["\n"] = "\\n", ["="] = "\\=", ["\\"] = "\\\\", }
local function escape(s) local function escape(s)
return s:gsub("[\\\n=]", escapes) return s:gsub("[\\\n=]", escapes)
end end
if output then if output then
local e
outfile, e = io.open(output, "w") outfile, e = io.open(output, "w")
if not outfile then if not outfile then
err("error opening file for writing: %s", e) err("error opening file for writing: %s", e)
end end
end end
local function printf(fmt, ...)
io.stdout:write(fmt:format(...))
end
local template_msgs = intllib.load_strings(template) local template_msgs = intllib.load_strings(template)
for _, file in ipairs(catalogs) do for _, file in ipairs(catalogs) do
@ -120,10 +108,12 @@ for _, file in ipairs(catalogs) do
for k, v in pairs(catalog_msgs) do for k, v in pairs(catalog_msgs) do
if not template_msgs[k] then if not template_msgs[k] then
print("OLD: "..k) print("OLD: "..k)
table.insert(dirty_lines, "OLD: "..escape(k).." = "..escape(v))
end end
end end
if #dirty_lines > 0 then if #dirty_lines > 0 then
local outf, e = io.open(file, "a+") local outf
outf, e = io.open(file, "a+")
if outf then if outf then
outf:write("\n") outf:write("\n")
for _, line in ipairs(dirty_lines) do for _, line in ipairs(dirty_lines) do