diff --git a/conf.lua b/conf.lua index f2c3ca0..4a59258 100644 --- a/conf.lua +++ b/conf.lua @@ -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) diff --git a/file.lua b/file.lua index 956b33c..cd2686e 100644 --- a/file.lua +++ b/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 +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) diff --git a/init.lua b/init.lua index 480ae8a..7ded956 100644 --- a/init.lua +++ b/init.lua @@ -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") -]] \ No newline at end of file +]] + +return modlib \ No newline at end of file diff --git a/math.lua b/math.lua index 70f396c..66723ef 100644 --- a/math.lua +++ b/math.lua @@ -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)