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
|
||||
return function(filtered, name, def)
|
||||
if def.type ~= "node" then return false end
|
||||
return filtered
|
||||
return filtered -- or nil
|
||||
end
|
||||
```
|
@ -3,8 +3,8 @@ local error, io, ipairs, loadfile, minetest, next, os, pairs, rawget,
|
||||
string, type
|
||||
= error, io, ipairs, loadfile, minetest, next, os, pairs, rawget,
|
||||
string, type
|
||||
local io_open, os_remove, string_gsub, string_match, string_sub
|
||||
= 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.sub
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local include = ...
|
||||
@ -77,13 +77,18 @@ local function exportall()
|
||||
outf:write("-- AUTOMATICALLY GENERATED by <https://gitlab.com/szest/defripper>"
|
||||
.. "\n\nlocal reg = ...\n\n")
|
||||
|
||||
local custom, err = loadfile(outdir .. "/customfilter.lua")
|
||||
if not custom then
|
||||
if not string_match(err, "No such file or directory") then
|
||||
return error(err)
|
||||
local hascustomlua
|
||||
for _, fn in pairs(minetest.get_dir_list(outdir, false)) do
|
||||
if fn == "customfilter.lua" then
|
||||
hascustomlua = true
|
||||
break
|
||||
end
|
||||
else
|
||||
custom = custom()
|
||||
end
|
||||
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
|
||||
return error("customfilter.lua must return filter function")
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user