266de35f87
Currently only used in pong.love, but let's keep the bad merge that had it broken since September from occurring again. To do that we'll be consistent across forks on where globals are initialized. I haven't appreciated the implications of main.lua for load order. log.lua comes first just because it's shared by both the main app and its 'source' editing environment. And it just so happens that source.lua was loading after log.lua resulting in the pong.love breakage. Now let's lean into that and enshrine that one should initialize log_render in log.lua.
38 lines
920 B
Lua
38 lines
920 B
Lua
function log(stack_frame_index, obj)
|
|
local info = debug.getinfo(stack_frame_index, 'Sl')
|
|
local msg
|
|
if type(obj) == 'string' then
|
|
msg = obj
|
|
else
|
|
msg = json.encode(obj)
|
|
end
|
|
love.filesystem.append('log', info.short_src..':'..info.currentline..': '..msg..'\n')
|
|
end
|
|
|
|
-- for section delimiters we'll use specific Unicode box characters
|
|
function log_start(name, stack_frame_index)
|
|
if stack_frame_index == nil then
|
|
stack_frame_index = 3
|
|
end
|
|
log(stack_frame_index, '\u{250c} ' .. name)
|
|
end
|
|
function log_end(name, stack_frame_index)
|
|
if stack_frame_index == nil then
|
|
stack_frame_index = 3
|
|
end
|
|
log(stack_frame_index, '\u{2518} ' .. name)
|
|
end
|
|
|
|
function log_new(name, stack_frame_index)
|
|
if stack_frame_index == nil then
|
|
stack_frame_index = 4
|
|
end
|
|
log_end(name, stack_frame_index)
|
|
log_start(name, stack_frame_index)
|
|
end
|
|
|
|
-- rendering graphical objects within sections/boxes
|
|
log_render = {}
|
|
|
|
-- vim:noexpandtab
|