diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-09-03 13:54:38 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-09-03 13:58:30 -0700 |
commit | 42762ce06290650fe5bec9b516c5dda9e2fd97fb (patch) | |
tree | 7c89f728302f911be738b4d78772293e68342253 /log.lua | |
parent | 8123959e52f8a82204156460162b05a0d68bca80 (diff) | |
download | text.love-42762ce06290650fe5bec9b516c5dda9e2fd97fb.tar.gz |
editing source code from within the app
integrated from pong.love: https://merveilles.town/@akkartik/108933336531898243
Diffstat (limited to 'log.lua')
-rw-r--r-- | log.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/log.lua b/log.lua new file mode 100644 index 0000000..f59449c --- /dev/null +++ b/log.lua @@ -0,0 +1,34 @@ +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 + +-- vim:noexpandtab |