v0.2.0 - Added startup apps and an event handler process (unfinished)

This commit is contained in:
TheWahlolly
2025-04-03 21:19:50 +03:00
parent 4adc959549
commit 7b8e237abe
10 changed files with 742 additions and 690 deletions
+2
View File
@@ -0,0 +1,2 @@
/halyde/core/shell.lua
/halyde/core/evmgr.lua
+2 -2
View File
@@ -1,7 +1,7 @@
local loadfile = ... local loadfile = ...
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile) local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
_G._OSVERSION = "Halyde 0.1.0" _G._OSVERSION = "Halyde 0.2.0"
function _G.import(module, ...) function _G.import(module, ...)
local args = table.pack(...) local args = table.pack(...)
@@ -21,7 +21,7 @@ function _G.import(module, ...)
tmpdata = handle:read(math.huge or math.maxinteger) tmpdata = handle:read(math.huge or math.maxinteger)
data = data .. (tmpdata or "") data = data .. (tmpdata or "")
until not tmpdata until not tmpdata
assert(load(data, "="..modulepath))(table.unpack(args)) return(assert(load(data, "="..modulepath))(table.unpack(args)))
end end
--local handle = assert(filesystem.open("/bazinga.txt", "w")) --local handle = assert(filesystem.open("/bazinga.txt", "w"))
+21 -3
View File
@@ -1,12 +1,15 @@
_G.cormgr = {} _G.cormgr = {}
_G.cormgr.corList = {} _G.cormgr.corList = {}
--local ocelot = component.proxy(component.list("ocelot")())
local filesystem = import("filesystem")
function _G.cormgr.loadCoroutine(path) function _G.cormgr.loadCoroutine(path)
local cor = coroutine.create(function() local cor = coroutine.create(function()
import(path) import(path)
end) end)
table.insert(_G.cormgr.corList, cor) table.insert(_G.cormgr.corList, cor)
coroutine.yield()
end end
function handleError(errormsg) function handleError(errormsg)
@@ -14,7 +17,19 @@ function handleError(errormsg)
assert(false, errormsg) assert(false, errormsg)
end end
_G.cormgr.loadCoroutine("/halyde/core/loader.lua") local handle = filesystem.open("/halyde/config/startupapps.txt", "r")
local data = ""
local tmpdata
repeat
tmpdata = handle:read(math.huge or math.maxinteger)
data = data .. (tmpdata or "")
until not tmpdata
for line in data:gmatch("([^\n]*)\n?") do
if line ~= "" then
_G.cormgr.loadCoroutine(line)
end
end
_G.cormgr.loadCoroutine("/halyde/core/shell.lua")
while true do while true do
for i = 1, #_G.cormgr.corList do for i = 1, #_G.cormgr.corList do
@@ -25,6 +40,9 @@ while true do
handleError(errormsg) handleError(errormsg)
end end
end end
computer.pullSignal(1) computer.pullSignal(0)
end
if #_G.cormgr.corList == 0 then
computer.shutdown()
end end
end end
+17
View File
@@ -0,0 +1,17 @@
_G.evmgr = {}
_G.evmgr.eventQueue = {}
local maxEventQueueLength = 10 -- increase if events start getting dropped
while true do
local args
repeat
args = computer.pullSignal(0)
if args then
table.insert(evmgr.eventQueue, table.pack(computer.uptime(), args))
while #evmgr.eventQueue > maxEventQueueLength do
table.remove(evmgr.eventQueue, 1)
end
end
until not args
coroutine.yield()
end
-8
View File
@@ -1,8 +0,0 @@
import("termlib")
print("wait...")
print("IT WORKS???")
print("abab")
print("abc\ndef")
print("abc\tdef")
print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
+6
View File
@@ -0,0 +1,6 @@
import("termlib")
print("\n\n".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n')
while true do
coroutine.yield()
end
+17
View File
@@ -0,0 +1,17 @@
local event = {}
function event.pull(timeout, type)
local startTime = computer.uptime()
local args
repeat
for _, eventArgs in ipairs(_G.evmgr.eventQueue) do
if eventArgs[1] >= startTime and (eventArgs[2] == type or not type) then
args = eventArgs
end
end
coroutine.yield()
until args
table.remove(args, 1)
return args
end
return event
+1 -1
View File
@@ -4,7 +4,7 @@ local component
if loadfile then if loadfile then
component = loadfile("/halyde/lib/component.lua")(loadfile) component = loadfile("/halyde/lib/component.lua")(loadfile)
else else
component = require("component") component = import("component")
end end
local filesystem = {} local filesystem = {}