helpers.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --[[
  2. Copyright 2017 Stefano Mazzucco <stefano AT curso DOT re>
  3. This program is free software: you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation, either version 3 of the License, or (at your option) any later
  6. version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
  13. ]]
  14. local helpers = {}
  15. function helpers.dir(obj, indent)
  16. indent = indent or ""
  17. if type(obj) == "table" then
  18. local out = "\n"
  19. for k, v in pairs(obj) do
  20. out = out ..
  21. indent ..
  22. helpers.dir(k) ..
  23. " :: " ..
  24. helpers.dir(v, indent .. " ") ..
  25. "\n"
  26. end
  27. return out
  28. else
  29. return indent .. tostring(obj)
  30. end
  31. end
  32. function helpers.concat_non_nil(values, sep)
  33. sep = sep or " "
  34. local text = ""
  35. for _, v in pairs(values) do
  36. text = text .. v .. sep
  37. end
  38. return text:sub(1, -2)
  39. end
  40. function helpers.reload(m)
  41. package.loaded[m] = nil
  42. return require(m)
  43. end
  44. return helpers