Improve error trace reporting

This commit is contained in:
aaron 2023-08-21 21:57:11 +01:00
parent ccb36df365
commit be15f69522
2 changed files with 19 additions and 2 deletions

View file

@ -1,8 +1,25 @@
local function get_path(s)
if string.sub(s, #s - 4, #s) == ".luau" then
s = string.sub(s, 1, #s - 5)
print("test, ", s)
end
return string.split(s, string.match(s, "%w+/") and "/" or ".")
end
local root do
local path = get_path(debug.info(1, "s"))
root = path[#path - 1]
end
local function throw(msg: string)
local stack = 1
while debug.info(stack, "s") == debug.info(1, "s") do
local path = get_path(debug.info(stack, "s"))
while path[#path] == root or path[#path - 1] == root do
stack += 1
path = get_path(debug.info(stack, "s"))
end
error(msg, stack)