add a mirror and reorg mirrors
[lines.love.git] / log.lua
blob8903e08575efecc6566c93b20562178d74cdddd8
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
12 -- for section delimiters we'll use specific Unicode box characters
13 function log_start(name, stack_frame_index)
14 if stack_frame_index == nil then
15 stack_frame_index = 3
16 end
17 -- I'd like to use the unicode character \u{250c} here, but it doesn't work
18 -- in OpenBSD.
19 log(stack_frame_index, '[ u250c ' .. name)
20 end
21 function log_end(name, stack_frame_index)
22 if stack_frame_index == nil then
23 stack_frame_index = 3
24 end
25 -- I'd like to use the unicode character \u{2518} here, but it doesn't work
26 -- in OpenBSD.
27 log(stack_frame_index, '] u2518 ' .. name)
28 end
30 function log_new(name, stack_frame_index)
31 if stack_frame_index == nil then
32 stack_frame_index = 4
33 end
34 log_end(name, stack_frame_index)
35 log_start(name, stack_frame_index)
36 end
38 -- rendering graphical objects within sections/boxes
39 log_render = {}
41 -- vim:noexpandtab