mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-01 19:53:59 +01:00
rolling-7
This commit is contained in:
parent
358cdf5084
commit
94e38087e6
2
conf.lua
2
conf.lua
@ -17,7 +17,7 @@ function load_or_create(filename, replacement_file, constraints)
|
|||||||
return load(filename, constraints)
|
return load(filename, constraints)
|
||||||
end
|
end
|
||||||
function import(modname,constraints)
|
function import(modname,constraints)
|
||||||
return load_or_create(get_path(modname)..".json",get_resource(modname, "default_config.json"),constraints)
|
return load_or_create(get_path(modname)..".json", modlib.mod.get_resource(modname, "default_config.json"),constraints)
|
||||||
end
|
end
|
||||||
function check_constraints(value, constraints)
|
function check_constraints(value, constraints)
|
||||||
local t=type(value)
|
local t=type(value)
|
||||||
|
27
init.lua
27
init.lua
@ -33,6 +33,11 @@ if _VERSION then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get modpath wrapper
|
||||||
|
local function get_resource(modname, resource)
|
||||||
|
return minetest.get_modpath(modname) .. "/" .. resource
|
||||||
|
end
|
||||||
|
|
||||||
local function loadfile_exports(filename)
|
local function loadfile_exports(filename)
|
||||||
local env = setmetatable({}, {__index = _G, __call = _G})
|
local env = setmetatable({}, {__index = _G, __call = _G})
|
||||||
local file = assert(loadfile(filename))
|
local file = assert(loadfile(filename))
|
||||||
@ -45,17 +50,17 @@ end
|
|||||||
|
|
||||||
local components = {
|
local components = {
|
||||||
mod = {},
|
mod = {},
|
||||||
class = {class = "global"},
|
class = {},
|
||||||
conf = {conf = "global"},
|
conf = {},
|
||||||
data = {data = "global"},
|
data = {},
|
||||||
file = {file_ext = "global"},
|
file = {},
|
||||||
log = {log = "global"},
|
log = {},
|
||||||
minetest = {mt_ext = "global"},
|
minetest = {},
|
||||||
number = {number_ext = "global"},
|
number = {},
|
||||||
player = {player_ext = "global"},
|
player = {},
|
||||||
table = {table_ext = "global"},
|
table = {},
|
||||||
text = {string_ext = "global", string = "local"},
|
text = {string = "local"},
|
||||||
threading = {threading_ext = "global"}
|
threading = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
modlib = {}
|
modlib = {}
|
||||||
|
15
mod.lua
15
mod.lua
@ -9,7 +9,7 @@ function include(modname, file)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- loadfile with table env
|
-- loadfile with table env
|
||||||
function include_class(classname, filename)
|
function include_namespace(classname, filename)
|
||||||
_G[classname] = setmetatable(_G[classname] or {}, {__index = _G, __call = _G})
|
_G[classname] = setmetatable(_G[classname] or {}, {__index = _G, __call = _G})
|
||||||
local class = assert(loadfile(filename))
|
local class = assert(loadfile(filename))
|
||||||
setfenv(class, _G[classname])
|
setfenv(class, _G[classname])
|
||||||
@ -18,15 +18,18 @@ function include_class(classname, filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- runs main.lua in table env
|
-- runs main.lua in table env
|
||||||
function include_mod(modname)
|
-- formerly include_mod
|
||||||
include_class(modname, get_resource(modname, "main.lua"))
|
function init(modname)
|
||||||
|
include_namespace(modname, get_resource(modname, "main.lua"))
|
||||||
end
|
end
|
||||||
|
|
||||||
function extend_mod(modname, filename)
|
-- formerly extend_mod
|
||||||
include_class(modname, get_resource(modname, filename .. ".lua"))
|
function extend(modname, filename)
|
||||||
|
include_namespace(modname, get_resource(modname, filename .. ".lua"))
|
||||||
end
|
end
|
||||||
|
|
||||||
function extend_mod_string(modname, string)
|
-- formerly extend_mod_string
|
||||||
|
function extend_string(modname, string)
|
||||||
_G[modname] = setmetatable(_G[modname] or {}, {__index = _G, __call = _G})
|
_G[modname] = setmetatable(_G[modname] or {}, {__index = _G, __call = _G})
|
||||||
local string = assert(loadstring(string))
|
local string = assert(loadstring(string))
|
||||||
setfenv(string, _G[modname])
|
setfenv(string, _G[modname])
|
||||||
|
@ -150,7 +150,7 @@ function unique(table)
|
|||||||
for val in ipairs(table) do
|
for val in ipairs(table) do
|
||||||
lookup[val] = true
|
lookup[val] = true
|
||||||
end
|
end
|
||||||
return table_ext.keys(lookup)
|
return keys(lookup)
|
||||||
end
|
end
|
||||||
|
|
||||||
function rpairs(t)
|
function rpairs(t)
|
||||||
@ -185,11 +185,11 @@ function best_value(table, is_better_fnc)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function min(table)
|
function min(table)
|
||||||
return table_ext.best_value(table, function(v, m) return v < m end)
|
return best_value(table, function(v, m) return v < m end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function max(table)
|
function max(table)
|
||||||
return table_ext.best_value(table, function(v, m) return v > m end)
|
return best_value(table, function(v, m) return v > m end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function binary_search(list, value)
|
function binary_search(list, value)
|
||||||
|
8
text.lua
8
text.lua
@ -37,7 +37,7 @@ function trim_begin(str, to_remove)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function split(str, delim, limit)
|
function split(str, delim, limit)
|
||||||
if not limit then return string_ext.split_without_limit(str, delim) end
|
if not limit then return split_without_limit(str, delim) end
|
||||||
local parts = {}
|
local parts = {}
|
||||||
local occurences = 1
|
local occurences = 1
|
||||||
local last_index = 1
|
local last_index = 1
|
||||||
@ -72,8 +72,8 @@ letter_a = string.byte("A")
|
|||||||
letter_f = string.byte("F")
|
letter_f = string.byte("F")
|
||||||
|
|
||||||
function is_hexadecimal(byte)
|
function is_hexadecimal(byte)
|
||||||
return (byte >= zero and byte <= string_ext.nine) or
|
return (byte >= zero and byte <= nine) or
|
||||||
(byte >= string_ext.letter_a and byte <= string_ext.letter_f)
|
(byte >= letter_a and byte <= letter_f)
|
||||||
end
|
end
|
||||||
|
|
||||||
magic_chars = {
|
magic_chars = {
|
||||||
@ -81,7 +81,7 @@ magic_chars = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function escape_magic_chars(text)
|
function escape_magic_chars(text)
|
||||||
for _, magic_char in ipairs(string_ext.magic_chars) do
|
for _, magic_char in ipairs(magic_chars) do
|
||||||
text = string.gsub(text, "%" .. magic_char, "%%" .. magic_char)
|
text = string.gsub(text, "%" .. magic_char, "%%" .. magic_char)
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
|
Loading…
Reference in New Issue
Block a user