mirror of
https://github.com/appgurueu/modlib.git
synced 2024-12-22 13:22:27 +01:00
Turn remaining MT-only modules into MT-submodules
Affects mod, log, conf & player. Preserves compat through aliases.
This commit is contained in:
parent
0a749b6e70
commit
7cf3bd2944
27
init.lua
27
init.lua
@ -63,17 +63,12 @@ for _, file in pairs{
|
||||
modules[file] = file
|
||||
end
|
||||
if minetest then
|
||||
for _, file in pairs{
|
||||
"minetest",
|
||||
"log",
|
||||
"player",
|
||||
-- deprecated
|
||||
"conf"
|
||||
} do
|
||||
modules[file] = file
|
||||
end
|
||||
modules.minetest = "minetest"
|
||||
end
|
||||
|
||||
-- aliases
|
||||
-- more aliases are implemented below:
|
||||
-- modlib.[mod|log|conf|player] are aliases of modlib.minetest.[mod|log|conf|player] respectively
|
||||
modules.string = "text"
|
||||
modules.number = "math"
|
||||
|
||||
@ -101,6 +96,10 @@ end
|
||||
local function load_module(self, module_name_or_alias)
|
||||
local module_name = modules[module_name_or_alias]
|
||||
if not module_name then
|
||||
-- Handle modlib.[log|player] aliases for the minetest.[log|player] modules
|
||||
if module_name_or_alias == "log" or module_name_or_alias == "player" then
|
||||
return modlib.minetest[module_name_or_alias]
|
||||
end
|
||||
-- no such module
|
||||
return
|
||||
end
|
||||
@ -142,8 +141,13 @@ modlib.file = assert(loadfile(get_resource"file.lua"))(dir_delim)
|
||||
modlib.file.concat_path = concat_path
|
||||
|
||||
if minetest then
|
||||
modlib.mod = dofile(get_resource(modlib.modname, "mod.lua"))
|
||||
modlib.mod.get_resource = get_resource
|
||||
-- Force-loading of the minetest, mod and conf modules.
|
||||
-- Also sets modlib.[mod|conf] -> modlib.minetest.[mod|conf] aliases.
|
||||
local ml_mt = modlib.minetest
|
||||
ml_mt.mod.get_resource = get_resource
|
||||
modlib.mod = ml_mt.mod
|
||||
ml_mt.conf.build_setting_tree()
|
||||
modlib.conf = ml_mt.conf
|
||||
-- HACK force load minetest/gametime.lua to ensure that the globalstep is registered earlier than globalsteps of mods depending on modlib
|
||||
dofile(get_resource(modlib.modname, "minetest", "gametime.lua"))
|
||||
local ie = minetest.request_insecure_environment()
|
||||
@ -152,7 +156,6 @@ if minetest then
|
||||
-- TODO currently no need to set _G.require, lsqlite3 loads no dependencies that way
|
||||
modlib.persistence = assert(loadfile(get_resource"persistence.lua"))(ie.require)
|
||||
end
|
||||
modlib.conf.build_setting_tree()
|
||||
end
|
||||
|
||||
-- Run build scripts
|
||||
|
21
minetest.lua
21
minetest.lua
@ -2,6 +2,10 @@ local _ENV = {}
|
||||
|
||||
local components = {}
|
||||
for _, value in pairs{
|
||||
"mod",
|
||||
"log",
|
||||
"player",
|
||||
"conf", -- deprecated
|
||||
"luon",
|
||||
"raycast",
|
||||
"schematic",
|
||||
@ -11,7 +15,11 @@ for _, value in pairs{
|
||||
} do
|
||||
components[value] = value
|
||||
end
|
||||
|
||||
-- These dirty files have to write to the modlib.minetest environment
|
||||
local dirty_files = {}
|
||||
for filename, comps in pairs{
|
||||
-- get_gametime is missing from here as it is forceloaded in init.lua
|
||||
misc = {
|
||||
"max_wear",
|
||||
"override",
|
||||
@ -60,13 +68,22 @@ for filename, comps in pairs{
|
||||
for _, component in pairs(comps) do
|
||||
components[component] = filename
|
||||
end
|
||||
dirty_files[filename] = true
|
||||
end
|
||||
|
||||
local modpath, concat_path = minetest.get_modpath(modlib.modname), modlib.file.concat_path
|
||||
|
||||
setmetatable(_ENV, {__index = function(_ENV, name)
|
||||
local filename = components[name]
|
||||
if filename then
|
||||
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
||||
return rawget(_ENV, name)
|
||||
local loader = assert(loadfile(concat_path{modpath, "minetest", filename .. ".lua"}))
|
||||
if dirty_files[filename] then
|
||||
loader(_ENV)
|
||||
return rawget(_ENV, name)
|
||||
end
|
||||
local module = loader()
|
||||
_ENV[name] = module
|
||||
return module
|
||||
end
|
||||
end})
|
||||
|
||||
|
@ -22,7 +22,7 @@ function build_tree(dict)
|
||||
end
|
||||
if minetest then
|
||||
function build_setting_tree()
|
||||
modlib.conf.settings = build_tree(minetest.settings:to_table())
|
||||
settings = build_tree(minetest.settings:to_table())
|
||||
end
|
||||
-- deprecated, use modlib.mod.configuration instead
|
||||
minetest.mkdir(minetest.get_worldpath().."/config")
|
||||
@ -118,7 +118,7 @@ function import(modname, constraints, no_settingtypes)
|
||||
local settingtypes = generate_settingtypes(default_conf, constraints)
|
||||
modlib.file.write(modlib.mod.get_resource(modname, "settingtypes.txt"), settingtypes)
|
||||
end
|
||||
local additional_settings = modlib.conf.settings[modname] or {}
|
||||
local additional_settings = settings[modname] or {}
|
||||
additional_settings = fix_types(additional_settings, constraints)
|
||||
-- TODO implement merge_config_legal(default_conf, ...)
|
||||
config = merge_config(config, additional_settings)
|
@ -11,7 +11,7 @@ local metatables = {
|
||||
-- TODO expand
|
||||
}
|
||||
|
||||
(...).luon = modlib.luon.new{
|
||||
return modlib.luon.new{
|
||||
aux_write = function(_, value)
|
||||
local type = metatables[getmetatable(value)]
|
||||
if type then
|
||||
|
@ -3,9 +3,6 @@ local minetest, modlib, pairs, ipairs
|
||||
|
||||
--! experimental
|
||||
|
||||
local _ENV = ...
|
||||
setfenv(1, _ENV)
|
||||
|
||||
-- TODO support for server texture packs (and possibly client TPs in singleplayer?)
|
||||
local media_foldernames = {"textures", "sounds", "media", "models", "locale"}
|
||||
local media_extensions = modlib.table.set{
|
||||
@ -53,4 +50,4 @@ for _, mod in ipairs(modlib.minetest.get_mod_load_order()) do
|
||||
end
|
||||
end
|
||||
|
||||
media = {paths = paths}
|
||||
return {paths = paths}
|
@ -6,7 +6,7 @@ local _ENV = ...
|
||||
setfenv(1, _ENV)
|
||||
|
||||
--+ Raycast wrapper with proper flowingliquid intersections
|
||||
function raycast(_pos1, _pos2, objects, liquids)
|
||||
local function raycast(_pos1, _pos2, objects, liquids)
|
||||
local raycast = minetest.raycast(_pos1, _pos2, objects, liquids)
|
||||
if not liquids then
|
||||
return raycast
|
||||
@ -138,4 +138,6 @@ function raycast(_pos1, _pos2, objects, liquids)
|
||||
return next()
|
||||
end
|
||||
return setmetatable({next = next}, {__call = next})
|
||||
end
|
||||
end
|
||||
|
||||
return raycast
|
@ -2,11 +2,8 @@
|
||||
local VoxelArea, ItemStack, assert, error, io, ipairs, math, minetest, modlib, next, pairs, setmetatable, string, table, type, vector
|
||||
= VoxelArea, ItemStack, assert, error, io, ipairs, math, minetest, modlib, next, pairs, setmetatable, string, table, type, vector
|
||||
|
||||
-- Set environment
|
||||
local _ENV = ...
|
||||
setfenv(1, _ENV)
|
||||
|
||||
schematic = {}
|
||||
local schematic = {}
|
||||
local metatable = {__index = schematic}
|
||||
|
||||
function schematic.setmetatable(self)
|
||||
@ -185,4 +182,6 @@ function schematic.read_zlib_bluon(path)
|
||||
local file = io.open(path, "rb")
|
||||
assert(file:read(4) == "MLZS", "not a modlib zlib compressed bluon schematic")
|
||||
return schematic.setmetatable(read_bluon(modlib.text.inputstream(minetest.decompress(file:read"*a", "deflate"))))
|
||||
end
|
||||
end
|
||||
|
||||
return schematic
|
Loading…
Reference in New Issue
Block a user