v0.4.0 - Aaaand event.lua is no longer working. FUUUUUUUUU
This commit is contained in:
@@ -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.3.1"
|
_G._OSVERSION = "Halyde 0.4.0"
|
||||||
|
|
||||||
function _G.import(module, ...)
|
function _G.import(module, ...)
|
||||||
local args = table.pack(...)
|
local args = table.pack(...)
|
||||||
@@ -28,4 +28,4 @@ end
|
|||||||
--assert(handle:write("Bazinga!"))
|
--assert(handle:write("Bazinga!"))
|
||||||
--handle:close()
|
--handle:close()
|
||||||
|
|
||||||
import("/halyde/core/cormgr.lua")
|
import("/halyde/core/cormgr.lua")
|
||||||
@@ -13,11 +13,10 @@ function _G.cormgr.loadCoroutine(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function handleError(errormsg)
|
function handleError(errormsg)
|
||||||
if errormsg~=nil then
|
if errormsg == nil then
|
||||||
-- nothing for now
|
error("unknown error")
|
||||||
error(tostring(errormsg))
|
|
||||||
else
|
else
|
||||||
error("An error has occured, but given as 'nil'.")
|
error(tostring(errormsg).."\n \n"..debug.traceback())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -59,4 +58,4 @@ while true do
|
|||||||
if #_G.cormgr.corList == 0 then
|
if #_G.cormgr.corList == 0 then
|
||||||
computer.shutdown()
|
computer.shutdown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -4,4 +4,19 @@ function table.find(table, item)
|
|||||||
return(v)
|
return(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function table.copy(orig)
|
||||||
|
local orig_type = type(orig)
|
||||||
|
local copy
|
||||||
|
if orig_type == 'table' then
|
||||||
|
copy = {}
|
||||||
|
for orig_key, orig_value in next, orig, nil do
|
||||||
|
copy[table.copy(orig_key)] = table.copy(orig_value)
|
||||||
|
end
|
||||||
|
setmetatable(copy, table.copy(getmetatable(orig)))
|
||||||
|
else -- number, string, boolean, etc
|
||||||
|
copy = orig
|
||||||
|
end
|
||||||
|
return copy
|
||||||
end
|
end
|
||||||
+8
-13
@@ -7,21 +7,16 @@ local ocelot = component.proxy(component.list("ocelot")())
|
|||||||
while true do
|
while true do
|
||||||
local args
|
local args
|
||||||
repeat
|
repeat
|
||||||
args = computer.pullSignal(0)
|
args = {computer.pullSignal(0)}
|
||||||
if args then
|
if args and args[1] then
|
||||||
ocelot.log("Sending signal "..args..","..computer.uptime())
|
--ocelot.log("Sending signal "..args..","..computer.uptime())
|
||||||
table.insert(evmgr.eventQueue, {computer.uptime(),args})
|
table.insert(evmgr.eventQueue, args)
|
||||||
while #evmgr.eventQueue > maxEventQueueLength do
|
while #evmgr.eventQueue > maxEventQueueLength do
|
||||||
ocelot.log("Queue length breach, removing first signal")
|
--ocelot.log("Queue length breach, removing first signal")
|
||||||
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 or not args[1]
|
||||||
|
--ocelot.log("done")
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
@@ -5,7 +5,7 @@ local event = import("event")
|
|||||||
|
|
||||||
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 = {event.pull("key_down")}
|
read()
|
||||||
--ocelot.log(tostring(args[1]))
|
--ocelot.log(tostring(args[1]))
|
||||||
end
|
end
|
||||||
+18
-15
@@ -2,30 +2,33 @@ local event = {}
|
|||||||
|
|
||||||
local ocelot = component.proxy(component.list("ocelot")())
|
local ocelot = component.proxy(component.list("ocelot")())
|
||||||
|
|
||||||
function event.pull(evtype, timeout)
|
function event.pull(evtype, ...)
|
||||||
|
local timeout = ...
|
||||||
checkArg(1, evtype, "string", "nil")
|
checkArg(1, evtype, "string", "nil")
|
||||||
checkArg(2, timeout, "number", "nil")
|
checkArg(2, timeout, "number", "nil")
|
||||||
local startTime = computer.uptime()
|
local startTime = computer.uptime()
|
||||||
local args
|
local args = {}
|
||||||
|
local finished = false
|
||||||
repeat
|
repeat
|
||||||
for i = 1, #evmgr.eventQueue do
|
for i = 1, #evmgr.eventQueue do
|
||||||
ocelot.log(tostring(evmgr.eventQueue[i][1]).." ("..type(evmgr.eventQueue[i][1]).."), "..tostring(evmgr.eventQueue[i][2]))
|
if evmgr.eventQueue[i][2] == evtype or not evtype then
|
||||||
--ocelot.log(tostring(evmgr.eventQueue[i][3]))
|
args = table.copy(evmgr.eventQueue[i])
|
||||||
--ocelot.log(tostring(evmgr.eventQueue[i][4]))
|
table.remove(evmgr.eventQueue, i)
|
||||||
if evmgr.eventQueue[i][1] >= startTime and (evmgr.eventQueue[i][2] == evtype or not evtype) then
|
|
||||||
args = evmgr.eventQueue[i]
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not args then
|
if evtype then
|
||||||
|
finished = args[1] == evtype
|
||||||
|
end
|
||||||
|
if timeout then
|
||||||
|
finished = computer.uptime() >= startTime + timeout
|
||||||
|
end
|
||||||
|
if not finished then
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
until args and not timeout or args and timeout and (args or computer.uptime() >= startTime + timeout)
|
until finished
|
||||||
if args then
|
ocelot.log(tostring(args[1]))
|
||||||
--[[ table.remove(args, 1)
|
return table.unpack(args)
|
||||||
return table.unpack(args) ]]
|
|
||||||
return args[2]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return event
|
return event
|
||||||
+36
-6
@@ -1,5 +1,11 @@
|
|||||||
|
|
||||||
|
local event = import("event")
|
||||||
|
--local keyboard = import("keyboard")
|
||||||
|
|
||||||
local gpu = component.proxy(component.list("gpu")()) -- replace with component.gpu once implemented
|
local gpu = component.proxy(component.list("gpu")()) -- replace with component.gpu once implemented
|
||||||
local lineNumber = 1
|
local ocelot = component.proxy(component.list("ocelot")())
|
||||||
|
_G.termlib = {}
|
||||||
|
termlib.nextPosX, termlib.nextPosY = 1, 1
|
||||||
|
|
||||||
function _G.print(text)
|
function _G.print(text)
|
||||||
local xRes, yRes = gpu.getResolution()
|
local xRes, yRes = gpu.getResolution()
|
||||||
@@ -9,17 +15,41 @@ function _G.print(text)
|
|||||||
local printText = tostring(text):gsub("\t", " ")
|
local printText = tostring(text):gsub("\t", " ")
|
||||||
for line in printText:gmatch("([^\n]*)\n?") do
|
for line in printText:gmatch("([^\n]*)\n?") do
|
||||||
while #line > xRes do
|
while #line > xRes do
|
||||||
gpu.set(1,lineNumber,line:sub(1,xRes))
|
gpu.set(termlib.nextPosX, termlib.nextPosY, line:sub(1,xRes))
|
||||||
line = line:sub(xRes+1)
|
line = line:sub(xRes+1)
|
||||||
lineNumber = lineNumber + 1
|
termlib.nextPosY = termlib.nextPosY + 1
|
||||||
|
termlib.nextPosX = 1
|
||||||
end
|
end
|
||||||
gpu.set(1,lineNumber,line)
|
gpu.set(termlib.nextPosX, termlib.nextPosY, line)
|
||||||
lineNumber = lineNumber + 1
|
termlib.nextPosY = termlib.nextPosY + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _G.clear()
|
function _G.clear()
|
||||||
local xRes, yRes = gpu.getResolution()
|
local xRes, yRes = gpu.getResolution()
|
||||||
gpu.fill(1,1,xRes,yRes," ")
|
gpu.fill(1,1,xRes,yRes," ")
|
||||||
lineNumber = 1
|
termlib.nextPosX, termlib.nextPosY = 1, 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function _G.read()
|
||||||
|
ocelot.log("reading")
|
||||||
|
local curtext = ""
|
||||||
|
local nextPosX, nextPosY = termlib.nextPosX, termlib.nextPosY
|
||||||
|
while true do
|
||||||
|
local args = {event.pull("key_down", 0.5)}
|
||||||
|
ocelot.log(tostring(args[1]))
|
||||||
|
if args[4] then
|
||||||
|
local keycode = args[4]
|
||||||
|
local key = keyboard.keys[keycode]
|
||||||
|
if key == "back" then
|
||||||
|
curtext = curtext:sub(1, #curtext-1)
|
||||||
|
elseif key == "enter" then
|
||||||
|
return curtext
|
||||||
|
else
|
||||||
|
curtext = curtext .. (unicode.char(args[3]) or "")
|
||||||
|
end
|
||||||
|
termlib.nextPosX, termlib.nextPosY = nextPosX, nextPosY
|
||||||
|
print(curtext)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user