about summary refs log tree commit diff stats
path: root/log.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-09-03 13:54:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-03 13:58:30 -0700
commit42762ce06290650fe5bec9b516c5dda9e2fd97fb (patch)
tree7c89f728302f911be738b4d78772293e68342253 /log.lua
parent8123959e52f8a82204156460162b05a0d68bca80 (diff)
downloadtext.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.lua34
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