v0.3.0 - Nothing works. I'm confused as hell. I can't figure this out.

This commit is contained in:
TheWahlolly
2025-04-05 16:21:58 +03:00
parent 7b8e237abe
commit 198b56e64a
8 changed files with 208 additions and 21 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
/halyde/core/shell.lua /halyde/core/datatools.lua
/halyde/core/evmgr.lua /halyde/core/evmgr.lua
/halyde/core/shell.lua
+17 -10
View File
@@ -17,6 +17,21 @@ function handleError(errormsg)
assert(false, errormsg) assert(false, errormsg)
end end
local function runCoroutines()
for i = 1, #_G.cormgr.corList do
local result, errorMessage = coroutine.resume(_G.cormgr.corList[i])
if not result then
handleError(errorMessage)
end
if coroutine.status(_G.cormgr.corList[i]) == "dead" then
table.remove(_G.cormgr.corList, i)
break
end
--computer.pullSignal(0)
--coroutine.yield()
end
end
local handle = filesystem.open("/halyde/config/startupapps.txt", "r") local handle = filesystem.open("/halyde/config/startupapps.txt", "r")
local data = "" local data = ""
local tmpdata local tmpdata
@@ -27,21 +42,13 @@ until not tmpdata
for line in data:gmatch("([^\n]*)\n?") do for line in data:gmatch("([^\n]*)\n?") do
if line ~= "" then if line ~= "" then
_G.cormgr.loadCoroutine(line) _G.cormgr.loadCoroutine(line)
runCoroutines()
end end
end end
_G.cormgr.loadCoroutine("/halyde/core/shell.lua") _G.cormgr.loadCoroutine("/halyde/core/shell.lua")
while true do while true do
for i = 1, #_G.cormgr.corList do runCoroutines()
local result, errormsg = coroutine.resume(_G.cormgr.corList[i])
if coroutine.status(_G.cormgr.corList[i]) == "dead" then
table.remove(_G.cormgr.corList, i)
if not result then
handleError(errormsg)
end
end
computer.pullSignal(0)
end
if #_G.cormgr.corList == 0 then if #_G.cormgr.corList == 0 then
computer.shutdown() computer.shutdown()
end end
+7
View File
@@ -0,0 +1,7 @@
function table.find(table, item)
for k, v in pairs(table) do
if v == item then
return(v)
end
end
end
+8
View File
@@ -2,6 +2,8 @@ _G.evmgr = {}
_G.evmgr.eventQueue = {} _G.evmgr.eventQueue = {}
local maxEventQueueLength = 10 -- increase if events start getting dropped local maxEventQueueLength = 10 -- increase if events start getting dropped
--local ocelot = component.proxy(component.list("ocelot")())
while true do while true do
local args local args
repeat repeat
@@ -11,6 +13,12 @@ while true do
while #evmgr.eventQueue > maxEventQueueLength do while #evmgr.eventQueue > maxEventQueueLength do
table.remove(evmgr.eventQueue, 1) table.remove(evmgr.eventQueue, 1)
end end
--ocelot.log("Event queue:")
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]))
end
end end
until not args until not args
coroutine.yield() coroutine.yield()
+144
View File
@@ -0,0 +1,144 @@
_G.keyboard = {pressedChars = {}, pressedCodes = {}}
_G.keyboard.keys = {}
keyboard.keys["1"] = 0x02
keyboard.keys["2"] = 0x03
keyboard.keys["3"] = 0x04
keyboard.keys["4"] = 0x05
keyboard.keys["5"] = 0x06
keyboard.keys["6"] = 0x07
keyboard.keys["7"] = 0x08
keyboard.keys["8"] = 0x09
keyboard.keys["9"] = 0x0A
keyboard.keys["0"] = 0x0B
keyboard.keys.a = 0x1E
keyboard.keys.b = 0x30
keyboard.keys.c = 0x2E
keyboard.keys.d = 0x20
keyboard.keys.e = 0x12
keyboard.keys.f = 0x21
keyboard.keys.g = 0x22
keyboard.keys.h = 0x23
keyboard.keys.i = 0x17
keyboard.keys.j = 0x24
keyboard.keys.k = 0x25
keyboard.keys.l = 0x26
keyboard.keys.m = 0x32
keyboard.keys.n = 0x31
keyboard.keys.o = 0x18
keyboard.keys.p = 0x19
keyboard.keys.q = 0x10
keyboard.keys.r = 0x13
keyboard.keys.s = 0x1F
keyboard.keys.t = 0x14
keyboard.keys.u = 0x16
keyboard.keys.v = 0x2F
keyboard.keys.w = 0x11
keyboard.keys.x = 0x2D
keyboard.keys.y = 0x15
keyboard.keys.z = 0x2C
keyboard.keys.apostrophe = 0x28
keyboard.keys.at = 0x91
keyboard.keys.back = 0x0E -- backspace
keyboard.keys.backslash = 0x2B
keyboard.keys.capital = 0x3A -- capslock
keyboard.keys.colon = 0x92
keyboard.keys.comma = 0x33
keyboard.keys.enter = 0x1C
keyboard.keys.equals = 0x0D
keyboard.keys.grave = 0x29 -- accent grave
keyboard.keys.lbracket = 0x1A
keyboard.keys.lcontrol = 0x1D
keyboard.keys.lmenu = 0x38 -- left Alt
keyboard.keys.lshift = 0x2A
keyboard.keys.minus = 0x0C
keyboard.keys.numlock = 0x45
keyboard.keys.pause = 0xC5
keyboard.keys.period = 0x34
keyboard.keys.rbracket = 0x1B
keyboard.keys.rcontrol = 0x9D
keyboard.keys.rmenu = 0xB8 -- right Alt
keyboard.keys.rshift = 0x36
keyboard.keys.scroll = 0x46 -- Scroll Lock
keyboard.keys.semicolon = 0x27
keyboard.keys.slash = 0x35 -- / on main keyboard
keyboard.keys.space = 0x39
keyboard.keys.stop = 0x95
keyboard.keys.tab = 0x0F
keyboard.keys.underline = 0x93
-- Keypad (and numpad with numlock off)
keyboard.keys.up = 0xC8
keyboard.keys.down = 0xD0
keyboard.keys.left = 0xCB
keyboard.keys.right = 0xCD
keyboard.keys.home = 0xC7
keyboard.keys["end"] = 0xCF
keyboard.keys.pageUp = 0xC9
keyboard.keys.pageDown = 0xD1
keyboard.keys.insert = 0xD2
keyboard.keys.delete = 0xD3
-- Function keys
keyboard.keys.f1 = 0x3B
keyboard.keys.f2 = 0x3C
keyboard.keys.f3 = 0x3D
keyboard.keys.f4 = 0x3E
keyboard.keys.f5 = 0x3F
keyboard.keys.f6 = 0x40
keyboard.keys.f7 = 0x41
keyboard.keys.f8 = 0x42
keyboard.keys.f9 = 0x43
keyboard.keys.f10 = 0x44
keyboard.keys.f11 = 0x57
keyboard.keys.f12 = 0x58
keyboard.keys.f13 = 0x64
keyboard.keys.f14 = 0x65
keyboard.keys.f15 = 0x66
keyboard.keys.f16 = 0x67
keyboard.keys.f17 = 0x68
keyboard.keys.f18 = 0x69
keyboard.keys.f19 = 0x71
-- Japanese keyboards
keyboard.keys.kana = 0x70
keyboard.keys.kanji = 0x94
keyboard.keys.convert = 0x79
keyboard.keys.noconvert = 0x7B
keyboard.keys.yen = 0x7D
keyboard.keys.circumflex = 0x90
keyboard.keys.ax = 0x96
-- Numpad
keyboard.keys.numpad0 = 0x52
keyboard.keys.numpad1 = 0x4F
keyboard.keys.numpad2 = 0x50
keyboard.keys.numpad3 = 0x51
keyboard.keys.numpad4 = 0x4B
keyboard.keys.numpad5 = 0x4C
keyboard.keys.numpad6 = 0x4D
keyboard.keys.numpad7 = 0x47
keyboard.keys.numpad8 = 0x48
keyboard.keys.numpad9 = 0x49
keyboard.keys.numpadmul = 0x37
keyboard.keys.numpaddiv = 0xB5
keyboard.keys.numpadsub = 0x4A
keyboard.keys.numpadadd = 0x4E
keyboard.keys.numpaddecimal = 0x53
keyboard.keys.numpadcomma = 0xB3
keyboard.keys.numpadenter = 0x9C
keyboard.keys.numpadequals = 0x8D
-- Create inverse mapping for name lookup.
setmetatable(keyboard.keys,
{
__index = function(tbl, k)
if type(k) ~= "number" then return end
for name,value in pairs(tbl) do
if value == k then
return name
end
end
end
})
+6 -1
View File
@@ -1,6 +1,11 @@
import("termlib") import("termlib")
local event = import("event")
--local ocelot = component.proxy(component.list("ocelot")())
print("\n\n".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n') print("\n\n".._OSVERSION..'\n │ Welcome! Type "help" to get started.\n')
while true do while true do
coroutine.yield() --coroutine.yield()
local args = table.pack(event.pull("key_down"))
--ocelot.log(tostring(args[1]))
end end
+21 -6
View File
@@ -1,17 +1,32 @@
local event = {} local event = {}
function event.pull(timeout, type) local ocelot = component.proxy(component.list("ocelot")())
function event.pull(type, timeout)
checkArg(1, type, "string", "nil")
checkArg(2, timeout, "number", "nil")
local startTime = computer.uptime() local startTime = computer.uptime()
local args local args
repeat repeat
for _, eventArgs in ipairs(_G.evmgr.eventQueue) do for i = 1, #evmgr.eventQueue do
if eventArgs[1] >= startTime and (eventArgs[2] == type or not type) then ocelot.log("Args 1 and 2:")
args = eventArgs 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
args = evmgr.eventQueue[i]
break
end end
end end
if not args then
coroutine.yield() coroutine.yield()
until args end
until args and not timeout or args and timeout and (args or computer.uptime() >= startTime + timeout)
if args then
table.remove(args, 1) table.remove(args, 1)
return args return table.unpack(args)
end
end end
return event return event
View File