about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-11-10 09:05:04 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-11-10 09:05:04 -0800
commit3007ea001406e5df96c353621f023425e52d10cb (patch)
treefad290ab465b766dddedd7466d432980441f1cf1
parentf737d63c691b21e54bd979a83fd24fcad46142a9 (diff)
parenta6738b49c4744431e49e075239203f4da7c76de3 (diff)
downloadview.love-3007ea001406e5df96c353621f023425e52d10cb.tar.gz
Merge lines.love
-rw-r--r--app.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/app.lua b/app.lua
index 841c632..a2f1f78 100644
--- a/app.lua
+++ b/app.lua
@@ -43,7 +43,8 @@ function love.run()
 end
 
 function handle_error(err)
-  Error_message = debug.traceback('Error: ' .. tostring(err), --[[stack frame]]2):gsub('\n[^\n]+$', '')
+  local callstack = debug.traceback('', --[[stack frame]]2)
+  Error_message = 'Error: ' .. tostring(err)..'\n'..clean_up_callstack(callstack)
   print(Error_message)
   if Current_app == 'run' then
     Settings.current_app = 'source'
@@ -56,6 +57,26 @@ function handle_error(err)
   end
 end
 
+-- I tend to read code from files myself (say using love.filesystem calls)
+-- rather than offload that to load().
+-- Functions compiled in this manner have ugly filenames of the form [string "filename"]
+-- This function cleans out this cruft from error callstacks.
+function clean_up_callstack(callstack)
+  local frames = {}
+  print(callstack)
+  for frame in string.gmatch(callstack, '[^\n]+\n*') do
+    local line = frame:gsub('^%s*(.-)\n?$', '%1')
+    local filename, rest = line:match('([^:]*):(.*)')
+    local core_filename = filename:match('^%[string "(.*)"%]$')
+    -- pass through frames that don't match this format
+    -- this includes the initial line "stack traceback:"
+    local new_frame = (core_filename or filename)..':'..rest
+    table.insert(frames, new_frame)
+  end
+  -- the initial "stack traceback:" line was unindented and remains so
+  return table.concat(frames, '\n\t')
+end
+
 -- The rest of this file wraps around various LÖVE primitives to support
 -- automated tests. Often tests will run with a fake version of a primitive
 -- that redirects to the real love.* version once we're done with tests.