From 91d9ebecb10ef2ac0abd7ee41fdd363d4ab334b7 Mon Sep 17 00:00:00 2001 From: TheWahlolly Date: Fri, 23 May 2025 15:34:50 +0300 Subject: [PATCH] v1.6.0 - Removed low level libraries computer and component. They must now be imported. --- argentum.cfg | 3 ++- argentum/store/halyde/package.cfg | 3 ++- halyde/apps/cp.lua | 2 +- halyde/apps/fetch.lua | 3 +++ halyde/apps/mv.lua | 2 +- halyde/config/startupapps.cfg | 1 - halyde/core/boot.lua | 26 +++++++++++++++++---- halyde/core/cormgr.lua | 1 + halyde/core/evmgr.lua | 2 ++ halyde/core/shell.lua | 1 + halyde/core/termlib.lua | 1 + halyde/lib/component.lua | 2 +- halyde/lib/computer.lua | 14 ++++++++++++ halyde/lib/event.lua | 3 ++- halyde/lib/filesystem.lua | 13 +++-------- init.lua | 38 +++++++++++++++---------------- 16 files changed, 75 insertions(+), 40 deletions(-) create mode 100644 halyde/lib/computer.lua diff --git a/argentum.cfg b/argentum.cfg index 1005888..e65c69c 100644 --- a/argentum.cfg +++ b/argentum.cfg @@ -1,7 +1,7 @@ local agcfg = { ["halyde"] = { ["maindir"] = "", - ["version"] = "1.5.0", + ["version"] = "1.6.0", ["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.", ["directories"] = { "halyde/apps", @@ -48,6 +48,7 @@ local agcfg = { "halyde/core/shell.lua", "halyde/core/termlib.lua", "halyde/lib/component.lua", + "halyde/lib/computer.lua", "halyde/lib/event.lua", "halyde/lib/filesystem.lua", "halyde/lib/raster.lua" diff --git a/argentum/store/halyde/package.cfg b/argentum/store/halyde/package.cfg index f4d591b..1a6cf14 100644 --- a/argentum/store/halyde/package.cfg +++ b/argentum/store/halyde/package.cfg @@ -4,7 +4,7 @@ Ahalyde/core/ Ahalyde/config/ Ahalyde/apps/helpdb/ Ahalyde/apps/ -V1.5.0 +V1.6.0 Ainit.lua Ahalyde/apps/helpdb/cat.txt Ahalyde/apps/helpdb/cd.txt @@ -41,6 +41,7 @@ Ahalyde/core/fullkb.lua Ahalyde/core/shell.lua Ahalyde/core/termlib.lua Ahalyde/lib/component.lua +Ahalyde/lib/computer.lua Ahalyde/lib/event.lua Ahalyde/lib/filesystem.lua Ahalyde/lib/raster.lua diff --git a/halyde/apps/cp.lua b/halyde/apps/cp.lua index cf6a8ab..ecd1316 100644 --- a/halyde/apps/cp.lua +++ b/halyde/apps/cp.lua @@ -19,7 +19,7 @@ if not fs.exists(fromFile) then print("\27[91mSource file does not exist.") return end -if fs.exists(toFile) and not (table.find(args, "-o") or table.find(args, "--overwrite")) then +if fs.exists(toFile) and not (table.find({...}, "-o") or table.find({...}, "--overwrite")) then print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.") return end diff --git a/halyde/apps/fetch.lua b/halyde/apps/fetch.lua index 2b3128d..0107a93 100644 --- a/halyde/apps/fetch.lua +++ b/halyde/apps/fetch.lua @@ -1,3 +1,6 @@ +local component = import("component") +local computer = import("computer") + local function printstat(text) termlib.cursorPosX = 35 print(text, true, false) diff --git a/halyde/apps/mv.lua b/halyde/apps/mv.lua index 8660759..6ffd880 100644 --- a/halyde/apps/mv.lua +++ b/halyde/apps/mv.lua @@ -17,7 +17,7 @@ end if not fs.exists(fromFile) then print("\27[91mSource file does not exist.") end -if fs.exists(toFile) and not (table.find(args, "-o") or table.find(args, "--overwrite")) then +if fs.exists(toFile) and not (table.find({...}, "-o") or table.find({...}, "--overwrite")) then print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.") return end diff --git a/halyde/config/startupapps.cfg b/halyde/config/startupapps.cfg index 0f8086c..6bc43df 100644 --- a/halyde/config/startupapps.cfg +++ b/halyde/config/startupapps.cfg @@ -1,4 +1,3 @@ -/halyde/core/datatools.lua /halyde/core/fullkb.lua /halyde/core/evmgr.lua /halyde/core/shell.lua diff --git a/halyde/core/boot.lua b/halyde/core/boot.lua index d3b9ee9..5db1f97 100644 --- a/halyde/core/boot.lua +++ b/halyde/core/boot.lua @@ -1,7 +1,7 @@ local loadfile = ... local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile) -_G._OSVERSION = "Halyde 1.5.0" +_G._OSVERSION = "Halyde 1.6.0" _G._OSLOGO = "" local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil repeat @@ -40,8 +40,15 @@ gpu.bind(screenAddress) --gpu.setResolution(targetWidth, targetHeight) gpu.setResolution(gpu.maxResolution()) +_G.package = {["preloaded"] = {}} + +loadfile("/halyde/core/datatools.lua")() + function _G.import(module, ...) local args = table.pack(...) + if package.preloaded[module] then + return package.preloaded[module] + end local modulepath if module:find("^/") then if filesystem.exists(module) then @@ -53,9 +60,7 @@ function _G.import(module, ...) modulepath = shell.workingDirectory..module end assert(modulepath, "module not found\npossible locations:\n/halyde/lib/"..module..".lua") - local handle = filesystem.open(modulepath) - local data = "" - local tmpdata = "" + local handle, data, tmpdata = filesystem.open(modulepath), "", nil repeat tmpdata = handle:read(math.huge or math.maxinteger) data = data .. (tmpdata or "") @@ -63,6 +68,19 @@ function _G.import(module, ...) return(assert(load(data, "="..modulepath))(table.unpack(args))) end +local function preload(module) + local handle, data, tmpdata = assert(filesystem.open("/halyde/lib/" .. module .. ".lua", "r")), "", nil + repeat + tmpdata = handle:read(math.huge or math.maxinteger) + data = data .. (tmpdata or "") + until not tmpdata + package.preloaded[module] = assert(load(data, "="..module))() + _G[module] = nil +end + +preload("component") +preload("computer") + --local handle = assert(filesystem.open("/bazinga.txt", "w")) --assert(handle:write("Bazinga!")) --handle:close() diff --git a/halyde/core/cormgr.lua b/halyde/core/cormgr.lua index 6ba210b..938cd0c 100644 --- a/halyde/core/cormgr.lua +++ b/halyde/core/cormgr.lua @@ -3,6 +3,7 @@ _G.cormgr.corList = {} --local ocelot = component.proxy(component.list("ocelot")()) +local component = import("component") local filesystem = import("filesystem") local gpu = component.proxy(component.list("gpu")()) diff --git a/halyde/core/evmgr.lua b/halyde/core/evmgr.lua index 9aae9f7..13cb13b 100644 --- a/halyde/core/evmgr.lua +++ b/halyde/core/evmgr.lua @@ -2,6 +2,8 @@ _G.evmgr = {} _G.evmgr.eventQueue = {} local maxEventQueueLength = 10 -- increase if events start getting dropped +local computer = import("computer") + keyboard.ctrlDown = false keyboard.altDown = false diff --git a/halyde/core/shell.lua b/halyde/core/shell.lua index cc3faa5..fbda683 100644 --- a/halyde/core/shell.lua +++ b/halyde/core/shell.lua @@ -2,6 +2,7 @@ local shellcfg = import("/halyde/config/shell.cfg") import("/halyde/core/termlib.lua") local event = import("event") local filesystem = import("filesystem") +local component = import("component") local gpu = component.proxy(component.list("gpu")()) _G.shell = {} diff --git a/halyde/core/termlib.lua b/halyde/core/termlib.lua index 018b1ca..8d6087d 100644 --- a/halyde/core/termlib.lua +++ b/halyde/core/termlib.lua @@ -2,6 +2,7 @@ local event = import("event") --local keyboard = import("keyboard") --local ocelot = component.proxy(component.list("ocelot")()) +local component = import("component") local gpu = component.proxy(component.list("gpu")()) -- replace with component.gpu once implemented _G.termlib = {} termlib.cursorPosX = 1 diff --git a/halyde/lib/component.lua b/halyde/lib/component.lua index b9c7e55..54b5058 100644 --- a/halyde/lib/component.lua +++ b/halyde/lib/component.lua @@ -19,4 +19,4 @@ end componentlib.invoke = component.invoke -return(componentlib) +return componentlib diff --git a/halyde/lib/computer.lua b/halyde/lib/computer.lua new file mode 100644 index 0000000..14a223f --- /dev/null +++ b/halyde/lib/computer.lua @@ -0,0 +1,14 @@ +local computerlib = table.copy(computer) +local LLcomputer = table.copy(computer) + +function computerlib.pullSignal(timeout) + local startTime = LLcomputer.uptime() + local result + repeat + result = {LLcomputer.pullSignal(0)} + coroutine.yield() + until result or timeout and LLcomputer.uptime() >= startTime + timeout + return table.unpack(result) +end + +return computerlib diff --git a/halyde/lib/event.lua b/halyde/lib/event.lua index afdbc41..65eefc9 100644 --- a/halyde/lib/event.lua +++ b/halyde/lib/event.lua @@ -1,3 +1,4 @@ +local computer = import("computer") local event = {} --local ocelot = component.proxy(component.list("ocelot")()) @@ -50,4 +51,4 @@ function event.pull(...) until false -- Loop until we find an event or timeout end -return event \ No newline at end of file +return event diff --git a/halyde/lib/filesystem.lua b/halyde/lib/filesystem.lua index c604ef7..1b3b69c 100644 --- a/halyde/lib/filesystem.lua +++ b/halyde/lib/filesystem.lua @@ -1,10 +1,12 @@ local loadfile = ... -- raw loadfile from boot.lua -local component +local component, computer if loadfile then component = loadfile("/halyde/lib/component.lua")(loadfile) + computer = _G.computer elseif import then component = import("component") + computer = import("computer") end local filesystem = {} @@ -127,15 +129,6 @@ function filesystem.size(path) return component.invoke(address, "size", absPath) end -function filesystem.isDirectory(path) - checkArg(1, path, "string") - local address, absPath = filesystem.absolutePath(path) - if not address then - return false - end - return component.invoke(address, "isDirectory", absPath) -end - function filesystem.rename(fromPath, toPath) checkArg(1, fromPath, "string") checkArg(2, toPath, "string") diff --git a/init.lua b/init.lua index 12f2b76..0e623ad 100644 --- a/init.lua +++ b/init.lua @@ -21,26 +21,26 @@ function loadthething() loadfile("/halyde/core/boot.lua")(loadfile) end -while true do +gpu.setBackground(0x000000) +gpu.fill(1, 1, resx, resy, " ") +local result, reason = xpcall(loadthething, handleError) +if not result then + local computer = import("computer") or computer gpu.setBackground(0x000000) gpu.fill(1, 1, resx, resy, " ") - local result, reason = xpcall(loadthething, handleError) - if not result then - gpu.setBackground(0x000000) - gpu.fill(1, 1, resx, resy, " ") - gpu.setBackground(0x800000) - gpu.setForeground(0xFFFFFF) - gpu.set(2,2,"A critical error has occurred.") - local i = 4 - reason = reason:gsub("\t", " ") - for line in string.gmatch((reason ~= nil and tostring(reason)) or "unknown error", "([^\n]*)\n?") do - gpu.set(2,i,line) - i = i + 1 - end - gpu.set(2,i+1, "Press any key to restart.") - local evname = "" - repeat - evname = computer.pullSignal() - until evname == "key_down" + gpu.setBackground(0x800000) + gpu.setForeground(0xFFFFFF) + gpu.set(2,2,"A critical error has occurred.") + local i = 4 + reason = reason:gsub("\t", " ") + for line in string.gmatch((reason ~= nil and tostring(reason)) or "unknown error", "([^\n]*)\n?") do + gpu.set(2,i,line) + i = i + 1 end + gpu.set(2,i+1, "Press any key to restart.") + local evname + repeat + evname = computer.pullSignal() + until evname == "key_down" + computer.shutdown(true) end