log.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function log(stack_frame_index, obj)
  2. local info = debug.getinfo(stack_frame_index, 'Sl')
  3. local msg
  4. if type(obj) == 'string' then
  5. msg = obj
  6. else
  7. msg = json.encode(obj)
  8. end
  9. love.filesystem.append('log', info.short_src..':'..info.currentline..': '..msg..'\n')
  10. end
  11. -- for section delimiters we'll use specific Unicode box characters
  12. function log_start(name, stack_frame_index)
  13. if stack_frame_index == nil then
  14. stack_frame_index = 3
  15. end
  16. -- I'd like to use the unicode character \u{250c} here, but it doesn't work
  17. -- in OpenBSD.
  18. log(stack_frame_index, '[ u250c ' .. name)
  19. end
  20. function log_end(name, stack_frame_index)
  21. if stack_frame_index == nil then
  22. stack_frame_index = 3
  23. end
  24. -- I'd like to use the unicode character \u{2518} here, but it doesn't work
  25. -- in OpenBSD.
  26. log(stack_frame_index, '] u2518 ' .. name)
  27. end
  28. function log_new(name, stack_frame_index)
  29. if stack_frame_index == nil then
  30. stack_frame_index = 4
  31. end
  32. log_end(name, stack_frame_index)
  33. log_start(name, stack_frame_index)
  34. end
  35. -- rendering graphical objects within sections/boxes
  36. log_render = {}
  37. -- vim:noexpandtab