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 14:13:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-09-03 14:13:22 -0700
commite1c5a42f311fdafd88506726bbe480f3fcc2d1a3 (patch)
tree6628729cc55947d0bd5d306704e88b57680c3514 /log.lua
parent9c72ff1bb4fc1ba08acfb0324079da6fe49f3a4a (diff)
downloadtext.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.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