Mod update

master
daretmavi 2021-03-04 23:39:47 +01:00
parent 4ebfdc1b01
commit 1cf0a66ac5
9 changed files with 104 additions and 19 deletions

View File

@ -117,7 +117,7 @@ origin https://notabug.org/tenplus1/mobs_redo (fetch)
Mod: lib_api/mobs_redo
origin https://github.com/appgurueu/modlib (fetch)
* master ca6757f [origin/master] table: get rid of unneeded metatable duplication
* master 63050f3 [origin/master] Add text.inputstream
Mod: lib_api/modlib
origin git@github.com:runsy/rcbows.git (fetch)
@ -153,7 +153,7 @@ origin https://codeberg.org/Hamlet/mobs_humans (fetch)
Mod: mobs/mobs_mobs/mobs_humans
origin https://notabug.org/TenPlus1/mobs_monster.git (fetch)
* master 57f40cf [origin/master] make cave spider tiny
* master 095d875 [origin/master] add Tree Creeper
Mod: mobs/mobs_mobs/mobs_monster
origin https://github.com/berengma/aerotest (fetch)
@ -161,7 +161,7 @@ origin https://github.com/berengma/aerotest (fetch)
Mod: mobs/mobs_mobkit/aerotest
origin https://github.com/runsy/petz (fetch)
* master 84e8b8f [origin/master] frogs improved
* master c3ae3ae [origin/master] Merge pull request #64 from NathanielFreeman/jackolantern
Mod: mobs/mobs_mobkit/petz
origin https://github.com/berengma/water_life (fetch)

View File

@ -13,13 +13,15 @@ function build_tree(dict)
end
return tree
end
function build_setting_tree()
modlib.conf.settings = build_tree(minetest.settings:to_table())
end
-- deprecated, use modlib.mod.configuration instead
minetest.mkdir(minetest.get_worldpath().."/config")
function get_path(confname)
return minetest.get_worldpath().."/config/"..confname
if minetest then
function build_setting_tree()
modlib.conf.settings = build_tree(minetest.settings:to_table())
end
-- deprecated, use modlib.mod.configuration instead
minetest.mkdir(minetest.get_worldpath().."/config")
function get_path(confname)
return minetest.get_worldpath().."/config/"..confname
end
end
function read_conf(text)
local lines = modlib.text.split_lines(text, nil, true)

View File

@ -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
if not minetest then return end
-- Process Bridge Helpers
process_bridges = {}
@ -73,7 +75,7 @@ end
function process_bridge_listen(name, line_consumer, step)
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 line = content:read()
while line do
@ -86,7 +88,7 @@ end
function process_bridge_serve(name, step)
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()
process_bridges[name].output_file = io.open(bridge.output, "a")
end)
@ -95,7 +97,6 @@ end
function process_bridge_write(name, message)
local bridge = process_bridges[name]
bridge.output_file:write(message .. "\n")
-- append(bridge.input, message)
end
function process_bridge_start(name, command, os_execute)

View File

@ -62,6 +62,15 @@ local function loadfile_exports(filename)
return env
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{
"mod",
"conf",
@ -83,20 +92,27 @@ for _, component in ipairs{
"ranked_set",
"b3d"
} 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
-- Aliases
modlib.string = modlib.text
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.loadfile_exports = loadfile_exports
modlib.mod.get_resource = get_resource
modlib.mod.loadfile_exports = loadfile_exports
end
_ml = modlib
--[[
--modlib.mod.include("test.lua")
]]
]]
return modlib

View File

@ -1,5 +1,5 @@
-- 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
function round(number, steps)
@ -48,4 +48,25 @@ function tostring(number, base, digit_function, precision)
end
end
return table.concat(out)
end
-- See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround#polyfill
function fround(number)
if number == 0 or number ~= number then
return number
end
local sign = 1
if number < 0 then
sign = -1
number = -number
end
local exp = math.floor(math.log(number, 2))
local powexp = 2 ^ math.max(-126, math.min(number, 127))
local leading = exp < -127 and 0 or 1
local mantissa = math.floor((leading - number / powexp) * 0x800000 + 0.5)
if mantissa <= -0x800000 then
return sign * math.huge
end
mantissa = mantissa / 0x800000
return sign * powexp * (leading - mantissa), mantissa
end

View File

@ -33,6 +33,29 @@ function shuffle(table)
return table
end
local rope_metatable = {__index = {
write = function(self, text)
table.insert(self, text)
end,
to_text = function(self)
return table.concat(self)
end
}}
--> rope with simple metatable (:write(text) and :to_text())
function rope(table)
return setmetatable(table or {}, rope_metatable)
end
local rope_len_metatable = {__index = {
write = function(self, text)
self.len = self.len + text:len()
end
}}
--> rope for determining length supporting :write(text), .len being the length
function rope_len(len)
return setmetatable({len = len or 0}, rope_len_metatable)
end
function is_circular(table)
assert(type(table) == "table")
local known = {}

View File

@ -27,6 +27,11 @@ do
assert(nilget({a = {}}, "a", "b", "c") == nil)
assert(nilget(nil, "a", "b", "c") == nil)
assert(nilget(nil, "a", nil, "c") == nil)
local rope = modlib.table.rope{}
rope:write"hello"
rope:write" "
rope:write"world"
assert(rope:to_text() == "hello world", rope:to_text())
end
-- heap

View File

@ -50,6 +50,19 @@ end
trim_right = trim_end
local inputstream_metatable = {
__index = {read = function(self, count)
local cursor = self.cursor + 1
self.cursor = self.cursor + count
local text = self.text:sub(cursor, self.cursor)
return text ~= "" and text or nil
end}
}
function inputstream(text)
return setmetatable({text = text, cursor = 0}, inputstream_metatable)
end
function split(text, delimiter, limit, is_regex)
limit = limit or math.huge
local no_regex = not is_regex

View File

@ -58,3 +58,7 @@ Mod: LessDirt/default
origin https://github.com/Treer/LessDirt.git (fetch)
* master 59d4434 [origin/master] Update forum link in README.md
Mod: LessDirt/default
origin https://github.com/Treer/LessDirt.git (fetch)
* master 59d4434 [origin/master] Update forum link in README.md
Mod: LessDirt/default