mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 01:03:46 +01:00
Move dir_delim to file module, add file.concat_path
This commit is contained in:
parent
277c076651
commit
c02a83aee8
7
file.lua
7
file.lua
@ -1,3 +1,4 @@
|
|||||||
|
local dir_delim = ...
|
||||||
-- Localize globals
|
-- Localize globals
|
||||||
local io, minetest, modlib, string = io, minetest, modlib, string
|
local io, minetest, modlib, string = io, minetest, modlib, string
|
||||||
|
|
||||||
@ -5,10 +6,12 @@ local io, minetest, modlib, string = io, minetest, modlib, string
|
|||||||
local _ENV = {}
|
local _ENV = {}
|
||||||
setfenv(1, _ENV)
|
setfenv(1, _ENV)
|
||||||
|
|
||||||
|
_ENV.dir_delim = dir_delim
|
||||||
|
|
||||||
function get_name(filepath)
|
function get_name(filepath)
|
||||||
assert(#modlib.dir_delim == 1)
|
return filepath:match(dir_delim .. "(.-)$") or filepath
|
||||||
return filepath:match(modlib.dir_delim .. "?(.-)$")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function split_extension(filename)
|
function split_extension(filename)
|
||||||
return filename:match"^(.*)%.(.*)$"
|
return filename:match"^(.*)%.(.*)$"
|
||||||
end
|
end
|
||||||
|
10
init.lua
10
init.lua
@ -81,13 +81,19 @@ if not minetest then
|
|||||||
parent_dir = init_path and init_path:match"^.[/\\]" or ""
|
parent_dir = init_path and init_path:match"^.[/\\]" or ""
|
||||||
end
|
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
|
-- only used if Minetest is available
|
||||||
local function get_resource(modname, resource, ...)
|
local function get_resource(modname, resource, ...)
|
||||||
if not resource then
|
if not resource then
|
||||||
resource = modname
|
resource = modname
|
||||||
modname = minetest.get_current_modname()
|
modname = minetest.get_current_modname()
|
||||||
end
|
end
|
||||||
return table.concat({minetest.get_modpath(modname), resource, ...}, modlib.dir_delim)
|
return concat_path{minetest.get_modpath(modname), resource, ...}
|
||||||
end
|
end
|
||||||
|
|
||||||
local rawget, rawset = rawget, rawset
|
local rawget, rawset = rawget, rawset
|
||||||
@ -95,8 +101,6 @@ modlib = setmetatable({
|
|||||||
-- TODO bump on release
|
-- TODO bump on release
|
||||||
version = 73,
|
version = 73,
|
||||||
modname = minetest and minetest.get_current_modname(),
|
modname = minetest and minetest.get_current_modname(),
|
||||||
-- TODO
|
|
||||||
dir_delim = rawget(_G, "DIR_DELIM") or "/",
|
|
||||||
_RG = setmetatable({}, {
|
_RG = setmetatable({}, {
|
||||||
__index = function(_, index)
|
__index = function(_, index)
|
||||||
return rawget(_G, index)
|
return rawget(_G, index)
|
||||||
|
Loading…
Reference in New Issue
Block a user