mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 09:13:53 +01:00
Make modlib independent of Minetest
This commit is contained in:
parent
d728157204
commit
44cca2569c
16
conf.lua
16
conf.lua
@ -13,13 +13,15 @@ function build_tree(dict)
|
|||||||
end
|
end
|
||||||
return tree
|
return tree
|
||||||
end
|
end
|
||||||
function build_setting_tree()
|
if minetest then
|
||||||
modlib.conf.settings = build_tree(minetest.settings:to_table())
|
function build_setting_tree()
|
||||||
end
|
modlib.conf.settings = build_tree(minetest.settings:to_table())
|
||||||
-- deprecated, use modlib.mod.configuration instead
|
end
|
||||||
minetest.mkdir(minetest.get_worldpath().."/config")
|
-- deprecated, use modlib.mod.configuration instead
|
||||||
function get_path(confname)
|
minetest.mkdir(minetest.get_worldpath().."/config")
|
||||||
return minetest.get_worldpath().."/config/"..confname
|
function get_path(confname)
|
||||||
|
return minetest.get_worldpath().."/config/"..confname
|
||||||
|
end
|
||||||
end
|
end
|
||||||
function read_conf(text)
|
function read_conf(text)
|
||||||
local lines = modlib.text.split_lines(text, nil, true)
|
local lines = modlib.text.split_lines(text, nil, true)
|
||||||
|
7
file.lua
7
file.lua
@ -47,6 +47,8 @@ end
|
|||||||
|
|
||||||
function create_if_not_exists_from_file(filename, src_filename) return create_if_not_exists(filename, read(src_filename)) end
|
function create_if_not_exists_from_file(filename, src_filename) return create_if_not_exists(filename, read(src_filename)) end
|
||||||
|
|
||||||
|
if not minetest then return end
|
||||||
|
|
||||||
-- Process Bridge Helpers
|
-- Process Bridge Helpers
|
||||||
process_bridges = {}
|
process_bridges = {}
|
||||||
|
|
||||||
@ -73,7 +75,7 @@ end
|
|||||||
|
|
||||||
function process_bridge_listen(name, line_consumer, step)
|
function process_bridge_listen(name, line_consumer, step)
|
||||||
local bridge = process_bridges[name]
|
local bridge = process_bridges[name]
|
||||||
modlib.minetest.register_globalstep(step or 0.1, function(dtime)
|
modlib.minetest.register_globalstep(step or 0.1, function()
|
||||||
local content = io.open(bridge.input, "r")
|
local content = io.open(bridge.input, "r")
|
||||||
local line = content:read()
|
local line = content:read()
|
||||||
while line do
|
while line do
|
||||||
@ -86,7 +88,7 @@ end
|
|||||||
|
|
||||||
function process_bridge_serve(name, step)
|
function process_bridge_serve(name, step)
|
||||||
local bridge = process_bridges[name]
|
local bridge = process_bridges[name]
|
||||||
modlib.minetest.register_globalstep(step or 0.1, function(dtime)
|
modlib.minetest.register_globalstep(step or 0.1, function()
|
||||||
bridge.output_file:close()
|
bridge.output_file:close()
|
||||||
process_bridges[name].output_file = io.open(bridge.output, "a")
|
process_bridges[name].output_file = io.open(bridge.output, "a")
|
||||||
end)
|
end)
|
||||||
@ -95,7 +97,6 @@ end
|
|||||||
function process_bridge_write(name, message)
|
function process_bridge_write(name, message)
|
||||||
local bridge = process_bridges[name]
|
local bridge = process_bridges[name]
|
||||||
bridge.output_file:write(message .. "\n")
|
bridge.output_file:write(message .. "\n")
|
||||||
-- append(bridge.input, message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function process_bridge_start(name, command, os_execute)
|
function process_bridge_start(name, command, os_execute)
|
||||||
|
26
init.lua
26
init.lua
@ -62,6 +62,15 @@ local function loadfile_exports(filename)
|
|||||||
return env
|
return env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local minetest_only = {
|
||||||
|
mod = true,
|
||||||
|
minetest = true,
|
||||||
|
data = true,
|
||||||
|
log = true,
|
||||||
|
player = true,
|
||||||
|
-- not actually minetest-only, but a deprecated component
|
||||||
|
conf = true
|
||||||
|
}
|
||||||
for _, component in ipairs{
|
for _, component in ipairs{
|
||||||
"mod",
|
"mod",
|
||||||
"conf",
|
"conf",
|
||||||
@ -83,20 +92,27 @@ for _, component in ipairs{
|
|||||||
"ranked_set",
|
"ranked_set",
|
||||||
"b3d"
|
"b3d"
|
||||||
} do
|
} do
|
||||||
modlib[component] = loadfile_exports(get_resource(component .. ".lua"))
|
if minetest or not minetest_only[component] then
|
||||||
|
local path = minetest and get_resource(component .. ".lua") or component .. ".lua"
|
||||||
|
modlib[component] = loadfile_exports(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Aliases
|
-- Aliases
|
||||||
modlib.string = modlib.text
|
modlib.string = modlib.text
|
||||||
modlib.number = modlib.math
|
modlib.number = modlib.math
|
||||||
|
|
||||||
modlib.conf.build_setting_tree()
|
if minetest then
|
||||||
|
modlib.conf.build_setting_tree()
|
||||||
|
|
||||||
modlib.mod.get_resource = get_resource
|
modlib.mod.get_resource = get_resource
|
||||||
modlib.mod.loadfile_exports = loadfile_exports
|
modlib.mod.loadfile_exports = loadfile_exports
|
||||||
|
end
|
||||||
|
|
||||||
_ml = modlib
|
_ml = modlib
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
--modlib.mod.include("test.lua")
|
--modlib.mod.include("test.lua")
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
return modlib
|
2
math.lua
2
math.lua
@ -1,5 +1,5 @@
|
|||||||
-- Make random random
|
-- Make random random
|
||||||
math.randomseed(minetest.get_us_time())
|
math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock())
|
||||||
for _ = 1, 100 do math.random() end
|
for _ = 1, 100 do math.random() end
|
||||||
|
|
||||||
function round(number, steps)
|
function round(number, steps)
|
||||||
|
Loading…
Reference in New Issue
Block a user