Move dir_delim to file module, add file.concat_path

This commit is contained in:
Lars Mueller 2021-11-06 18:30:57 +01:00
parent 277c076651
commit c02a83aee8
2 changed files with 12 additions and 5 deletions

@ -1,3 +1,4 @@
local dir_delim = ...
-- Localize globals
local io, minetest, modlib, string = io, minetest, modlib, string
@ -5,10 +6,12 @@ local io, minetest, modlib, string = io, minetest, modlib, string
local _ENV = {}
setfenv(1, _ENV)
_ENV.dir_delim = dir_delim
function get_name(filepath)
assert(#modlib.dir_delim == 1)
return filepath:match(modlib.dir_delim .. "?(.-)$")
return filepath:match(dir_delim .. "(.-)$") or filepath
end
function split_extension(filename)
return filename:match"^(.*)%.(.*)$"
end

@ -81,13 +81,19 @@ if not minetest then
parent_dir = init_path and init_path:match"^.[/\\]" or ""
end
local dir_delim = rawget(_G, "DIR_DELIM") or (package and package.config and assert(package.config:match("^(.-)[\r\n]"))) or "/"
local function concat_path(path)
return table.concat(path, dir_delim)
end
-- only used if Minetest is available
local function get_resource(modname, resource, ...)
if not resource then
resource = modname
modname = minetest.get_current_modname()
end
return table.concat({minetest.get_modpath(modname), resource, ...}, modlib.dir_delim)
return concat_path{minetest.get_modpath(modname), resource, ...}
end
local rawget, rawset = rawget, rawset
@ -95,8 +101,6 @@ modlib = setmetatable({
-- TODO bump on release
version = 73,
modname = minetest and minetest.get_current_modname(),
-- TODO
dir_delim = rawget(_G, "DIR_DELIM") or "/",
_RG = setmetatable({}, {
__index = function(_, index)
return rawget(_G, index)