diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-09-03 14:13:22 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-09-03 14:13:22 -0700 |
commit | e1c5a42f311fdafd88506726bbe480f3fcc2d1a3 (patch) | |
tree | 6628729cc55947d0bd5d306704e88b57680c3514 /log.lua | |
parent | 9c72ff1bb4fc1ba08acfb0324079da6fe49f3a4a (diff) | |
download | text.love-e1c5a42f311fdafd88506726bbe480f3fcc2d1a3.tar.gz |
editing source code from within the app
integrated from pong.love via text.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 |