init.lua 858 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. local mt = minetest
  2. ---@alias rr.LogLevel mt.LogLevel|0|1|2|3|4|5
  3. local log_levels = {
  4. [0] = "none",
  5. [1] = "verbose",
  6. [2] = "info",
  7. [3] = "action",
  8. [4] = "warning",
  9. [5] = "error",
  10. }
  11. ---@param path string
  12. local function require(path)
  13. return dofile(mt.get_modpath(mt.get_current_modname()) .. "/" .. path)
  14. end
  15. local inspect = require "inspect.lua"
  16. ---@param vars table
  17. ---@param depth integer|nil Default: `0`.
  18. ---@param level rr.LogLevel|nil Default: `0`.
  19. function log(vars, depth, level)
  20. level = level or 0
  21. if type(level) == "number" then level = log_levels[level] end
  22. level = level --[[@as string]]
  23. depth = depth or 0
  24. if depth == 0 then depth = math.huge end
  25. local l = mt.log
  26. local d = { depth = depth }
  27. for name, var in pairs(vars) do
  28. l(level, ("[%s]: %s \n\n"):format(inspect(name, d), inspect(var, d)))
  29. end
  30. end