From 6f1508d1bf54e734dcac75d0c230195e89be0196 Mon Sep 17 00:00:00 2001 From: Ponali Date: Tue, 8 Apr 2025 19:55:23 +0200 Subject: [PATCH 1/2] v0.3.1 - Fixed the infamous bug TheWahlolly didn't know that arrays were stored in pointers when set into another variable, affecting the original array. I also made some changes into the code for ocelot logs so signals are much clearer to investigate (I hope). --- halyde/core/boot.lua | 2 +- halyde/core/cormgr.lua | 15 +++++++++++---- halyde/core/evmgr.lua | 8 +++++--- halyde/core/shell.lua | 4 ++-- halyde/lib/event.lua | 21 ++++++++++----------- init.lua | 2 +- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/halyde/core/boot.lua b/halyde/core/boot.lua index e147733..7019351 100644 --- a/halyde/core/boot.lua +++ b/halyde/core/boot.lua @@ -28,4 +28,4 @@ end --assert(handle:write("Bazinga!")) --handle:close() -import("/halyde/core/cormgr.lua") \ No newline at end of file +import("/halyde/core/cormgr.lua") diff --git a/halyde/core/cormgr.lua b/halyde/core/cormgr.lua index 219e678..6f79595 100644 --- a/halyde/core/cormgr.lua +++ b/halyde/core/cormgr.lua @@ -13,8 +13,12 @@ function _G.cormgr.loadCoroutine(path) end function handleError(errormsg) - -- nothing for now - assert(false, errormsg) + if errormsg~=nil then + -- nothing for now + error(tostring(errormsg)) + else + error("An error has occured, but given as 'nil'.") + end end local function runCoroutines() @@ -41,15 +45,18 @@ repeat until not tmpdata for line in data:gmatch("([^\n]*)\n?") do if line ~= "" then + --[[ if _G.print then + print(line) + end ]] _G.cormgr.loadCoroutine(line) runCoroutines() end end -_G.cormgr.loadCoroutine("/halyde/core/shell.lua") +-- _G.cormgr.loadCoroutine("/halyde/core/shell.lua") while true do runCoroutines() if #_G.cormgr.corList == 0 then computer.shutdown() end -end \ No newline at end of file +end diff --git a/halyde/core/evmgr.lua b/halyde/core/evmgr.lua index 32394ce..b9ea6aa 100644 --- a/halyde/core/evmgr.lua +++ b/halyde/core/evmgr.lua @@ -2,15 +2,17 @@ _G.evmgr = {} _G.evmgr.eventQueue = {} local maxEventQueueLength = 10 -- increase if events start getting dropped ---local ocelot = component.proxy(component.list("ocelot")()) +local ocelot = component.proxy(component.list("ocelot")()) while true do local args repeat args = computer.pullSignal(0) if args then - table.insert(evmgr.eventQueue, table.pack(computer.uptime(), args)) + ocelot.log("Sending signal "..args..","..computer.uptime()) + table.insert(evmgr.eventQueue, {computer.uptime(),args}) while #evmgr.eventQueue > maxEventQueueLength do + ocelot.log("Queue length breach, removing first signal") table.remove(evmgr.eventQueue, 1) end --ocelot.log("Event queue:") @@ -22,4 +24,4 @@ while true do end until not args coroutine.yield() -end \ No newline at end of file +end diff --git a/halyde/core/shell.lua b/halyde/core/shell.lua index 22acc45..919a4be 100644 --- a/halyde/core/shell.lua +++ b/halyde/core/shell.lua @@ -6,6 +6,6 @@ local event = import("event") print("\n │\n │ ".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n │') while true do --coroutine.yield() - local args = table.pack(event.pull("key_down")) + local args = {event.pull("key_down")} --ocelot.log(tostring(args[1])) -end \ No newline at end of file +end diff --git a/halyde/lib/event.lua b/halyde/lib/event.lua index befa124..d6dd5dd 100644 --- a/halyde/lib/event.lua +++ b/halyde/lib/event.lua @@ -2,19 +2,17 @@ local event = {} local ocelot = component.proxy(component.list("ocelot")()) -function event.pull(type, timeout) - checkArg(1, type, "string", "nil") +function event.pull(evtype, timeout) + checkArg(1, evtype, "string", "nil") checkArg(2, timeout, "number", "nil") local startTime = computer.uptime() local args repeat for i = 1, #evmgr.eventQueue do - ocelot.log("Args 1 and 2:") - ocelot.log(tostring(evmgr.eventQueue[i][1])) - ocelot.log(tostring(evmgr.eventQueue[i][2])) - ocelot.log(tostring(evmgr.eventQueue[i][3])) - ocelot.log(tostring(evmgr.eventQueue[i][4])) - if evmgr.eventQueue[i][1] >= startTime and (evmgr.eventQueue[i][2] == type or not type) then + ocelot.log(tostring(evmgr.eventQueue[i][1]).." ("..type(evmgr.eventQueue[i][1]).."), "..tostring(evmgr.eventQueue[i][2])) + --ocelot.log(tostring(evmgr.eventQueue[i][3])) + --ocelot.log(tostring(evmgr.eventQueue[i][4])) + if evmgr.eventQueue[i][1] >= startTime and (evmgr.eventQueue[i][2] == evtype or not evtype) then args = evmgr.eventQueue[i] break end @@ -24,9 +22,10 @@ function event.pull(type, timeout) end until args and not timeout or args and timeout and (args or computer.uptime() >= startTime + timeout) if args then - table.remove(args, 1) - return table.unpack(args) + --[[ table.remove(args, 1) + return table.unpack(args) ]] + return args[2] end end -return event \ No newline at end of file +return event diff --git a/init.lua b/init.lua index 9b0914b..7232f03 100644 --- a/init.lua +++ b/init.lua @@ -43,4 +43,4 @@ while true do evname = computer.pullSignal() until evname == "key_down" end -end \ No newline at end of file +end From 247d32112c31d2ecdfe6b077bb2885a83dbac4ea Mon Sep 17 00:00:00 2001 From: Ponali Date: Tue, 8 Apr 2025 20:04:21 +0200 Subject: [PATCH 2/2] v0.3.1 (again) - I forgot to update the version in the file :/ --- halyde/core/boot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/halyde/core/boot.lua b/halyde/core/boot.lua index 7019351..0d0b512 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 0.2.0" +_G._OSVERSION = "Halyde 0.3.1" function _G.import(module, ...) local args = table.pack(...)