mirror of
https://github.com/appgurueu/modlib.git
synced 2024-08-20 05:14:10 +02: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
|
modules[file] = file
|
||||||
end
|
end
|
||||||
if minetest then
|
if minetest then
|
||||||
for _, file in pairs{
|
modules.minetest = "minetest"
|
||||||
"minetest",
|
|
||||||
"log",
|
|
||||||
"player",
|
|
||||||
-- deprecated
|
|
||||||
"conf"
|
|
||||||
} do
|
|
||||||
modules[file] = file
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- aliases
|
-- 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.string = "text"
|
||||||
modules.number = "math"
|
modules.number = "math"
|
||||||
|
|
||||||
@ -101,6 +96,10 @@ end
|
|||||||
local function load_module(self, module_name_or_alias)
|
local function load_module(self, module_name_or_alias)
|
||||||
local module_name = modules[module_name_or_alias]
|
local module_name = modules[module_name_or_alias]
|
||||||
if not module_name then
|
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
|
-- no such module
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -142,8 +141,13 @@ modlib.file = assert(loadfile(get_resource"file.lua"))(dir_delim)
|
|||||||
modlib.file.concat_path = concat_path
|
modlib.file.concat_path = concat_path
|
||||||
|
|
||||||
if minetest then
|
if minetest then
|
||||||
modlib.mod = dofile(get_resource(modlib.modname, "mod.lua"))
|
-- Force-loading of the minetest, mod and conf modules.
|
||||||
modlib.mod.get_resource = get_resource
|
-- 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
|
-- 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"))
|
dofile(get_resource(modlib.modname, "minetest", "gametime.lua"))
|
||||||
local ie = minetest.request_insecure_environment()
|
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
|
-- TODO currently no need to set _G.require, lsqlite3 loads no dependencies that way
|
||||||
modlib.persistence = assert(loadfile(get_resource"persistence.lua"))(ie.require)
|
modlib.persistence = assert(loadfile(get_resource"persistence.lua"))(ie.require)
|
||||||
end
|
end
|
||||||
modlib.conf.build_setting_tree()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Run build scripts
|
-- Run build scripts
|
||||||
|
19
minetest.lua
19
minetest.lua
@ -2,6 +2,10 @@ local _ENV = {}
|
|||||||
|
|
||||||
local components = {}
|
local components = {}
|
||||||
for _, value in pairs{
|
for _, value in pairs{
|
||||||
|
"mod",
|
||||||
|
"log",
|
||||||
|
"player",
|
||||||
|
"conf", -- deprecated
|
||||||
"luon",
|
"luon",
|
||||||
"raycast",
|
"raycast",
|
||||||
"schematic",
|
"schematic",
|
||||||
@ -11,7 +15,11 @@ for _, value in pairs{
|
|||||||
} do
|
} do
|
||||||
components[value] = value
|
components[value] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- These dirty files have to write to the modlib.minetest environment
|
||||||
|
local dirty_files = {}
|
||||||
for filename, comps in pairs{
|
for filename, comps in pairs{
|
||||||
|
-- get_gametime is missing from here as it is forceloaded in init.lua
|
||||||
misc = {
|
misc = {
|
||||||
"max_wear",
|
"max_wear",
|
||||||
"override",
|
"override",
|
||||||
@ -60,14 +68,23 @@ for filename, comps in pairs{
|
|||||||
for _, component in pairs(comps) do
|
for _, component in pairs(comps) do
|
||||||
components[component] = filename
|
components[component] = filename
|
||||||
end
|
end
|
||||||
|
dirty_files[filename] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local modpath, concat_path = minetest.get_modpath(modlib.modname), modlib.file.concat_path
|
||||||
|
|
||||||
setmetatable(_ENV, {__index = function(_ENV, name)
|
setmetatable(_ENV, {__index = function(_ENV, name)
|
||||||
local filename = components[name]
|
local filename = components[name]
|
||||||
if filename then
|
if filename then
|
||||||
assert(loadfile(modlib.mod.get_resource(modlib.modname, "minetest", filename .. ".lua")))(_ENV)
|
local loader = assert(loadfile(concat_path{modpath, "minetest", filename .. ".lua"}))
|
||||||
|
if dirty_files[filename] then
|
||||||
|
loader(_ENV)
|
||||||
return rawget(_ENV, name)
|
return rawget(_ENV, name)
|
||||||
end
|
end
|
||||||
|
local module = loader()
|
||||||
|
_ENV[name] = module
|
||||||
|
return module
|
||||||
|
end
|
||||||
end})
|
end})
|
||||||
|
|
||||||
return _ENV
|
return _ENV
|
@ -22,7 +22,7 @@ function build_tree(dict)
|
|||||||
end
|
end
|
||||||
if minetest then
|
if minetest then
|
||||||
function build_setting_tree()
|
function build_setting_tree()
|
||||||
modlib.conf.settings = build_tree(minetest.settings:to_table())
|
settings = build_tree(minetest.settings:to_table())
|
||||||
end
|
end
|
||||||
-- deprecated, use modlib.mod.configuration instead
|
-- deprecated, use modlib.mod.configuration instead
|
||||||
minetest.mkdir(minetest.get_worldpath().."/config")
|
minetest.mkdir(minetest.get_worldpath().."/config")
|
||||||
@ -118,7 +118,7 @@ function import(modname, constraints, no_settingtypes)
|
|||||||
local settingtypes = generate_settingtypes(default_conf, constraints)
|
local settingtypes = generate_settingtypes(default_conf, constraints)
|
||||||
modlib.file.write(modlib.mod.get_resource(modname, "settingtypes.txt"), settingtypes)
|
modlib.file.write(modlib.mod.get_resource(modname, "settingtypes.txt"), settingtypes)
|
||||||
end
|
end
|
||||||
local additional_settings = modlib.conf.settings[modname] or {}
|
local additional_settings = settings[modname] or {}
|
||||||
additional_settings = fix_types(additional_settings, constraints)
|
additional_settings = fix_types(additional_settings, constraints)
|
||||||
-- TODO implement merge_config_legal(default_conf, ...)
|
-- TODO implement merge_config_legal(default_conf, ...)
|
||||||
config = merge_config(config, additional_settings)
|
config = merge_config(config, additional_settings)
|
@ -11,7 +11,7 @@ local metatables = {
|
|||||||
-- TODO expand
|
-- TODO expand
|
||||||
}
|
}
|
||||||
|
|
||||||
(...).luon = modlib.luon.new{
|
return modlib.luon.new{
|
||||||
aux_write = function(_, value)
|
aux_write = function(_, value)
|
||||||
local type = metatables[getmetatable(value)]
|
local type = metatables[getmetatable(value)]
|
||||||
if type then
|
if type then
|
||||||
|
@ -3,9 +3,6 @@ local minetest, modlib, pairs, ipairs
|
|||||||
|
|
||||||
--! experimental
|
--! experimental
|
||||||
|
|
||||||
local _ENV = ...
|
|
||||||
setfenv(1, _ENV)
|
|
||||||
|
|
||||||
-- TODO support for server texture packs (and possibly client TPs in singleplayer?)
|
-- TODO support for server texture packs (and possibly client TPs in singleplayer?)
|
||||||
local media_foldernames = {"textures", "sounds", "media", "models", "locale"}
|
local media_foldernames = {"textures", "sounds", "media", "models", "locale"}
|
||||||
local media_extensions = modlib.table.set{
|
local media_extensions = modlib.table.set{
|
||||||
@ -53,4 +50,4 @@ for _, mod in ipairs(modlib.minetest.get_mod_load_order()) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
media = {paths = paths}
|
return {paths = paths}
|
@ -6,7 +6,7 @@ local _ENV = ...
|
|||||||
setfenv(1, _ENV)
|
setfenv(1, _ENV)
|
||||||
|
|
||||||
--+ Raycast wrapper with proper flowingliquid intersections
|
--+ 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)
|
local raycast = minetest.raycast(_pos1, _pos2, objects, liquids)
|
||||||
if not liquids then
|
if not liquids then
|
||||||
return raycast
|
return raycast
|
||||||
@ -139,3 +139,5 @@ function raycast(_pos1, _pos2, objects, liquids)
|
|||||||
end
|
end
|
||||||
return setmetatable({next = next}, {__call = next})
|
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
|
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
|
= 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}
|
local metatable = {__index = schematic}
|
||||||
|
|
||||||
function schematic.setmetatable(self)
|
function schematic.setmetatable(self)
|
||||||
@ -186,3 +183,5 @@ function schematic.read_zlib_bluon(path)
|
|||||||
assert(file:read(4) == "MLZS", "not a modlib zlib compressed bluon schematic")
|
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"))))
|
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