mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-29 10:43:43 +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)
|
||||
end
|
||||
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
|
||||
function check_constraints(value, constraints)
|
||||
local t=type(value)
|
||||
|
27
init.lua
27
init.lua
@ -33,6 +33,11 @@ if _VERSION then
|
||||
end
|
||||
end
|
||||
|
||||
-- get modpath wrapper
|
||||
local function get_resource(modname, resource)
|
||||
return minetest.get_modpath(modname) .. "/" .. resource
|
||||
end
|
||||
|
||||
local function loadfile_exports(filename)
|
||||
local env = setmetatable({}, {__index = _G, __call = _G})
|
||||
local file = assert(loadfile(filename))
|
||||
@ -45,17 +50,17 @@ end
|
||||
|
||||
local components = {
|
||||
mod = {},
|
||||
class = {class = "global"},
|
||||
conf = {conf = "global"},
|
||||
data = {data = "global"},
|
||||
file = {file_ext = "global"},
|
||||
log = {log = "global"},
|
||||
minetest = {mt_ext = "global"},
|
||||
number = {number_ext = "global"},
|
||||
player = {player_ext = "global"},
|
||||
table = {table_ext = "global"},
|
||||
text = {string_ext = "global", string = "local"},
|
||||
threading = {threading_ext = "global"}
|
||||
class = {},
|
||||
conf = {},
|
||||
data = {},
|
||||
file = {},
|
||||
log = {},
|
||||
minetest = {},
|
||||
number = {},
|
||||
player = {},
|
||||
table = {},
|
||||
text = {string = "local"},
|
||||
threading = {}
|
||||
}
|
||||
|
||||
modlib = {}
|
||||
|
15
mod.lua
15
mod.lua
@ -9,7 +9,7 @@ function include(modname, file)
|
||||
end
|
||||
|
||||
-- loadfile with table env
|
||||
function include_class(classname, filename)
|
||||
function include_namespace(classname, filename)
|
||||
_G[classname] = setmetatable(_G[classname] or {}, {__index = _G, __call = _G})
|
||||
local class = assert(loadfile(filename))
|
||||
setfenv(class, _G[classname])
|
||||
@ -18,15 +18,18 @@ function include_class(classname, filename)
|
||||
end
|
||||
|
||||
-- runs main.lua in table env
|
||||
function include_mod(modname)
|
||||
include_class(modname, get_resource(modname, "main.lua"))
|
||||
-- formerly include_mod
|
||||
function init(modname)
|
||||
include_namespace(modname, get_resource(modname, "main.lua"))
|
||||
end
|
||||
|
||||
function extend_mod(modname, filename)
|
||||
include_class(modname, get_resource(modname, filename .. ".lua"))
|
||||
-- formerly extend_mod
|
||||
function extend(modname, filename)
|
||||
include_namespace(modname, get_resource(modname, filename .. ".lua"))
|
||||
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})
|
||||
local string = assert(loadstring(string))
|
||||
setfenv(string, _G[modname])
|
||||
|
@ -150,7 +150,7 @@ function unique(table)
|
||||
for val in ipairs(table) do
|
||||
lookup[val] = true
|
||||
end
|
||||
return table_ext.keys(lookup)
|
||||
return keys(lookup)
|
||||
end
|
||||
|
||||
function rpairs(t)
|
||||
@ -185,11 +185,11 @@ function best_value(table, is_better_fnc)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
function binary_search(list, value)
|
||||
|
8
text.lua
8
text.lua
@ -37,7 +37,7 @@ function trim_begin(str, to_remove)
|
||||
end
|
||||
|
||||
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 occurences = 1
|
||||
local last_index = 1
|
||||
@ -72,8 +72,8 @@ letter_a = string.byte("A")
|
||||
letter_f = string.byte("F")
|
||||
|
||||
function is_hexadecimal(byte)
|
||||
return (byte >= zero and byte <= string_ext.nine) or
|
||||
(byte >= string_ext.letter_a and byte <= string_ext.letter_f)
|
||||
return (byte >= zero and byte <= nine) or
|
||||
(byte >= letter_a and byte <= letter_f)
|
||||
end
|
||||
|
||||
magic_chars = {
|
||||
@ -81,7 +81,7 @@ magic_chars = {
|
||||
}
|
||||
|
||||
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)
|
||||
end
|
||||
return text
|
||||
|
Loading…
Reference in New Issue
Block a user