Skip to content

Commit 6e0ac42

Browse files
authored
miniOS kernel 0.6.1.2
Now features debug tracebacks!
1 parent 126e153 commit 6e0ac42

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

miniOS/minios.lua

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_G._OSNAME = "miniOS"
2-
_G._OSVER = "0.6.1.1"
2+
_G._OSVER = "0.6.1.2"
33
_G._OSVERSION = _OSNAME .. " " .. _OSVER
44

55
--component code
@@ -1181,7 +1181,36 @@ end
11811181
local function runfile(file, ...)
11821182
local program, reason = loadfile(file)
11831183
if program then
1184-
local result = table.pack(pcall(program, ...))
1184+
local targs = {...}
1185+
local traceback
1186+
local result = table.pack(xpcall(program,
1187+
function(err) traceback = debug.traceback(nil, 2); return err end,
1188+
...))
1189+
--local result = table.pack(pcall(program, ...))
1190+
if traceback then
1191+
local function dropsame(s1,s2)
1192+
t1,t2={},{}
1193+
for l in s1:gmatch("(.-)\n") do t1[#t1+1] = l end
1194+
for l in s2:gmatch("(.-)\n") do t2[#t2+1] = l end
1195+
for i = #t1,1,-1 do
1196+
if t1[i] == t2[i] then
1197+
t1[i] = nil
1198+
t2[i] = nil
1199+
else
1200+
break
1201+
end
1202+
end
1203+
os1,os2 = "",""
1204+
for k,v in ipairs(t1) do
1205+
os1 = os1 .. v .. "\n"
1206+
end
1207+
for k,v in ipairs(t2) do
1208+
os2 = os2 .. v .. "\n"
1209+
end
1210+
return os1,os2
1211+
end
1212+
traceback = dropsame(traceback, debug.traceback(nil, 2)) .. "\t..."
1213+
end
11851214
if result[1] then
11861215
return table.unpack(result, 2, result.n)
11871216
else
@@ -1194,7 +1223,7 @@ local function runfile(file, ...)
11941223
--end
11951224
return
11961225
end end end
1197-
error(result[2], 3)
1226+
error(result[2] .. "\n" .. traceback, 3)
11981227
end
11991228
else
12001229
error(reason, 3)
@@ -1207,10 +1236,9 @@ end
12071236
function miniOS.saferunfile(...)
12081237
local r = {pcall(runfile, ...)}
12091238
if not r[1] then
1210-
printErr(r[2])
12111239
local c = component.gpu.getForeground()
12121240
component.gpu.setForeground(0xFF0000)
1213-
printPaged(r[3])
1241+
printPaged(r[2])
12141242
component.gpu.setForeground(c)
12151243
end
12161244
return r

0 commit comments

Comments
 (0)