Skip to content

Commit 3b21a8a

Browse files
authored
miniOS 0.6..1 kernel
1 parent 0fe06a4 commit 3b21a8a

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

miniOS/minios.lua

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

55
--component code
@@ -507,9 +507,9 @@ function fs_code()
507507
function fs.drive.drivepathSplit(mixed)
508508
local drive = fs.drive._current
509509
local path
510-
if mixed:sub(2,2) == ":" then
511-
drive = mixed:sub(1,1):upper()
512-
path = mixed:sub(3)
510+
if string.sub(mixed, 2,2) == ":" then
511+
drive = string.sub(mixed, 1,1):upper()
512+
path = string.sub(mixed, 3)
513513
else
514514
path = mixed
515515
end
@@ -1100,7 +1100,6 @@ function printPaged(...)
11001100
end
11011101
end
11021102
end
1103-
11041103
end
11051104
--load programs
11061105
function loadfile(file, mode, env)
@@ -1168,6 +1167,7 @@ miniOS = {}
11681167
local function interrupt(data)
11691168
--print("INTERRUPT!")
11701169
if data[2] == "RUN" then return miniOS.runfile(data[3], table.unpack(data[4])) end
1170+
if data[3] == "ERR" then error("This error is for testing!") end
11711171
end
11721172
local function runfile(file, ...)
11731173
local program, reason = loadfile(file)
@@ -1176,7 +1176,15 @@ local function runfile(file, ...)
11761176
if result[1] then
11771177
return table.unpack(result, 2, result.n)
11781178
else
1179-
if type(result[2]) == "table" then if result[2][1] then if result[2][1] == "INTERRUPT" then interrupt(result[2]) return true end end end
1179+
if type(result[2]) == "table" then if result[2][1] then if result[2][1] == "INTERRUPT" then
1180+
result = {interrupt(result[2])}
1181+
--if not result[1] then
1182+
--error(result[2], 3)
1183+
--else
1184+
--return table.unpack(result, 2, result.n)
1185+
--end
1186+
return
1187+
end end end
11801188
error(result[2], 3)
11811189
end
11821190
else
@@ -1187,26 +1195,52 @@ local function kernelError()
11871195
printErr("\nPress any key to try again.")
11881196
term.readKey()
11891197
end
1198+
function miniOS.saferunfile(...)
1199+
local r = {pcall(runfile, ...)}
1200+
if not r[1] then
1201+
printErr(r[2])
1202+
local c = component.gpu.getForeground()
1203+
component.gpu.setForeground(0xFF0000)
1204+
printPaged(debug.traceback())
1205+
component.gpu.setForeground(c)
1206+
end
1207+
return r
1208+
end
11901209
function miniOS.runfile(...)
1191-
local s, v = pcall(runfile, ...)
1192-
if not s then
1193-
printErr(err)
1194-
--printErr("\n" .. debug.traceback())
1195-
end
1196-
return v
1210+
local r = miniOS.saferunfile(...)
1211+
return table.unpack(r, 2, r.n)
1212+
end
1213+
1214+
local function tryrunlib(lib)
1215+
local ret
1216+
local opt = {lib .. ".lua", lib}
1217+
for _,o in ipairs(opt) do
1218+
if fs.exists(o) then
1219+
return miniOS.runfile(o)
1220+
end
1221+
end
1222+
error("Can't find the library specified: `" .. lib .. "`", 3)
11971223
end
11981224
function require(lib)
1199-
return _G[lib] or _G[string.lower(lib)] or miniOS.runfile(lib .. ".lua")
1225+
return _G[lib] or _G[string.lower(lib)] or tryrunlib(lib)
1226+
end
1227+
local function shellrun(...)
1228+
local success = miniOS.saferunfile(...)[1]
1229+
if not success then
1230+
printErr("\n\nError in running command interpreter.")
1231+
return false
1232+
end
1233+
return true
12001234
end
12011235

12021236
miniOS.freeMem = computer.freeMemory()
12031237

12041238
--start command and keep it running.
1205-
local command_drive = fs.drive.getcurrent()
1206-
if filesystem.exists("autoexec.bat") then miniOS.runfile("command.lua", "autoexec.bat") else miniOS.runfile("command.lua") end
1239+
local fallback_drive = fs.drive.getcurrent()
1240+
if filesystem.exists("autoexec.bat") then shellrun("command.lua", "autoexec.bat") else shellrun("command.lua") end
12071241
while true do
12081242
miniOS.freeMem = computer.freeMemory()
12091243
print()
1210-
fs.drive.setcurrent(command_drive)
1211-
if not miniOS.runfile("command.lua", "-c") then printErr("\n\nError during shell! Will restart command.lua!") kernelError() end
1244+
fs.drive.setcurrent(fallback_drive)
1245+
if not shellrun("command.lua", "-c") then printErr("Will restart command interpreter..."); kernelError() end
12121246
end

0 commit comments

Comments
 (0)