Fix custom filter i18n failure
When a language establishes a convention of using plain strings as exception types instead of something custom that can hold e.g. a "code" property, it effectively waives its right to i18n its error messages, or else programs cannot differentiate between types of errors and catch/pcall constructs are of very limited use. Unfortunately it seems that Lua did not realize this, and loadfile returns a plain string that is not usable due to i18n. Rather than trying to catch the "file not found" error, do a scan to look for the file first, and if it's found in the directory listing, assume any errors that happen on loading it are fatal.
This commit is contained in:
parent
cb2fd44773
commit
f0b79ad9fc
@ -116,6 +116,6 @@ Example `customfilter.lua` that excludes all non-node items:
|
|||||||
```lua
|
```lua
|
||||||
return function(filtered, name, def)
|
return function(filtered, name, def)
|
||||||
if def.type ~= "node" then return false end
|
if def.type ~= "node" then return false end
|
||||||
return filtered
|
return filtered -- or nil
|
||||||
end
|
end
|
||||||
```
|
```
|
@ -3,8 +3,8 @@ local error, io, ipairs, loadfile, minetest, next, os, pairs, rawget,
|
|||||||
string, type
|
string, type
|
||||||
= error, io, ipairs, loadfile, minetest, next, os, pairs, rawget,
|
= error, io, ipairs, loadfile, minetest, next, os, pairs, rawget,
|
||||||
string, type
|
string, type
|
||||||
local io_open, os_remove, string_gsub, string_match, string_sub
|
local io_open, os_remove, string_gsub, string_sub
|
||||||
= io.open, os.remove, string.gsub, string.match, string.sub
|
= io.open, os.remove, string.gsub, string.sub
|
||||||
-- LUALOCALS > ---------------------------------------------------------
|
-- LUALOCALS > ---------------------------------------------------------
|
||||||
|
|
||||||
local include = ...
|
local include = ...
|
||||||
@ -77,13 +77,18 @@ local function exportall()
|
|||||||
outf:write("-- AUTOMATICALLY GENERATED by <https://gitlab.com/szest/defripper>"
|
outf:write("-- AUTOMATICALLY GENERATED by <https://gitlab.com/szest/defripper>"
|
||||||
.. "\n\nlocal reg = ...\n\n")
|
.. "\n\nlocal reg = ...\n\n")
|
||||||
|
|
||||||
local custom, err = loadfile(outdir .. "/customfilter.lua")
|
local hascustomlua
|
||||||
if not custom then
|
for _, fn in pairs(minetest.get_dir_list(outdir, false)) do
|
||||||
if not string_match(err, "No such file or directory") then
|
if fn == "customfilter.lua" then
|
||||||
return error(err)
|
hascustomlua = true
|
||||||
|
break
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
custom = custom()
|
local custom
|
||||||
|
if hascustomlua then
|
||||||
|
local loaded, err = loadfile(outdir .. "/customfilter.lua")
|
||||||
|
if not loaded then return error(err) end
|
||||||
|
custom = loaded()
|
||||||
if type(custom) ~= "function" then
|
if type(custom) ~= "function" then
|
||||||
return error("customfilter.lua must return filter function")
|
return error("customfilter.lua must return filter function")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user