mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +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
|
||||
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
|
||||
|
10
init.lua
10
init.lua
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user