Minetest mod to have more useful error dumps using StackTracePlus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2KB

  1. local secenv = _G
  2. local modname = minetest.get_current_modname()
  3. local sec = (minetest.settings:get('secure.enable_security') == 'true')
  4. local ie
  5. -- //MFF (Mg|01/07/2016 for classic#508, hg#104, sb#166, creative#68)
  6. if (rawget(_G, "rawlen") == nil) then
  7. rawlen = {} -- That's extremely bad, but our only mean of stopping StackTracePlus from complaining about rawlen being undefined
  8. end
  9. if sec then
  10. ie = minetest.request_insecure_environment()
  11. if ie == nil then
  12. error("Mod security is on but " .. modname .. " is not whitelisted as a secure mod")
  13. end
  14. end
  15. if sec then
  16. string, io, debug, coroutine = ie.string, ie.io, ie.debug, ie.coroutine
  17. end
  18. local STP = dofile(minetest.get_modpath(modname) .. '/StackTracePlus/src/StackTracePlus.lua')
  19. -- Remove string/table dump length limits
  20. STP.max_tb_output_len = math.huge
  21. if sec then
  22. ie.debug.traceback = STP.stacktrace
  23. -- StackTracePlus caches the following modules, reset them to the original ones to
  24. -- avoid leaking them
  25. string, io, debug, coroutine = secenv.string, secenv.io, secenv.debug, secenv.coroutine
  26. ie = nil
  27. end
  28. debug.traceback = STP.stacktrace
  29. minetest.log('action', "[" .. modname .. "] replaced debug.traceback")