diff --git a/README.md b/README.md index e9e7298..08d7d8d 100644 --- a/README.md +++ b/README.md @@ -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 ``` \ No newline at end of file diff --git a/exportall.lua b/exportall.lua index 650e271..32773b6 100644 --- a/exportall.lua +++ b/exportall.lua @@ -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 " .. "\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