Initial commit
This commit is contained in:
commit
326fe0886f
0
depends.txt
Normal file
0
depends.txt
Normal file
52
init.lua
Normal file
52
init.lua
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
--
|
||||
-- To add debug support to a mod, add "moddebug?" to depends.txt, and add these
|
||||
-- lines to the top of any file where debug logging might be needed:
|
||||
--
|
||||
-- local dbg
|
||||
-- if moddebug then dbg=moddebug.dbg("modname") else dbg={v1=function() end,v2=function() end,v3=function() end} end
|
||||
--
|
||||
-- Then, anywhere something needs logging, use dbg.v1("message"). Or v2, or v3.
|
||||
-- There are three levels of verbosity, v1 is the lowest, v3 is the highest or
|
||||
-- most verbose and detailed.
|
||||
--
|
||||
|
||||
moddebug = {}
|
||||
|
||||
-- A dbg instance for each mod that requests one.
|
||||
moddebug.dbgs = {}
|
||||
|
||||
-- TODO - load/save config for this stuff, and add UI (or just chat commands?)
|
||||
-- to dynamically switch it
|
||||
moddebug.levels = {
|
||||
railcarts=3,
|
||||
barrel=3,
|
||||
health=3,
|
||||
}
|
||||
|
||||
moddebug.dbg = function(modname)
|
||||
if moddebug.dbgs[modname] then return moddebug.dbgs[modname] end
|
||||
local level = moddebug.levels[modname] or 0
|
||||
print("LOG level for "..modname.." is "..level)
|
||||
local m = string.upper(modname)
|
||||
local dbg = {
|
||||
}
|
||||
if level >= 1 then
|
||||
dbg.v1 = function(x) minetest.log("info", m..":"..x) end
|
||||
else
|
||||
dbg.v1 = function() end
|
||||
end
|
||||
if level >= 2 then
|
||||
dbg.v2 = function(x) minetest.log("info", m..":"..x) end
|
||||
else
|
||||
dbg.v2 = function() end
|
||||
end
|
||||
if level >= 3 then
|
||||
dbg.v3 = function(x) minetest.log("info", m..":"..x) end
|
||||
else
|
||||
dbg.v3 = function() end
|
||||
end
|
||||
moddebug.dbgs[modname] = dbg
|
||||
return dbg
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user