Merge branch 'Pyroxenium:master' into master

This commit is contained in:
Erlend
2022-07-27 16:26:58 +02:00
committed by GitHub
3 changed files with 18 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ local debugger = true
local projectDirectory = fs.getDir(table.pack(...)[2] or "") local projectDirectory = fs.getDir(table.pack(...)[2] or "")
local activeKey, frames, monFrames, variables, shedules = {}, {}, {}, {}, {} local activeKey, frames, monFrames, variables, schedules = {}, {}, {}, {}, {}
local mainFrame, activeFrame, focusedObject, updaterActive local mainFrame, activeFrame, focusedObject, updaterActive
if not term.isColor or not term.isColor() then if not term.isColor or not term.isColor() then
@@ -122,13 +122,13 @@ local basaltError = function(errMsg)
baseTerm.setCursorPos(1,yPos+1) baseTerm.setCursorPos(1,yPos+1)
end end
local function handleShedules(event, p1, p2, p3, p4) local function handleSchedules(event, p1, p2, p3, p4)
if(#shedules>0)then if(#schedules>0)then
local finished = {} local finished = {}
for n=1,#shedules do for n=1,#schedules do
if(shedules[n]~=nil)then if(schedules[n]~=nil)then
if (coroutine.status(shedules[n]) == "suspended")then if (coroutine.status(schedules[n]) == "suspended")then
local ok, result = coroutine.resume(shedules[n], event, p1, p2, p3, p4) local ok, result = coroutine.resume(schedules[n], event, p1, p2, p3, p4)
if not(ok)then if not(ok)then
basaltError(result) basaltError(result)
end end
@@ -138,7 +138,7 @@ local function handleShedules(event, p1, p2, p3, p4)
end end
end end
for n=1,#finished do for n=1,#finished do
table.remove(shedules, finished[n]-(n-1)) table.remove(schedules, finished[n]-(n-1))
end end
end end
end end
@@ -197,7 +197,7 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
for _, v in pairs(frames) do for _, v in pairs(frames) do
v:eventHandler(event, p1, p2, p3, p4) v:eventHandler(event, p1, p2, p3, p4)
end end
handleShedules(event, p1, p2, p3, p4) handleSchedules(event, p1, p2, p3, p4)
drawFrames() drawFrames()
end end
@@ -272,13 +272,13 @@ basalt = {
end end
end, end,
shedule = function(f) schedule = function(f)
assert(f~="function", "Shedule needs a function in order to work!") assert(f~="function", "Schedule needs a function in order to work!")
return function(...) return function(...)
local co = coroutine.create(f) local co = coroutine.create(f)
local ok, result = coroutine.resume(co, ...) local ok, result = coroutine.resume(co, ...)
if(ok)then if(ok)then
table.insert(shedules, co) table.insert(schedules, co)
else else
basaltError(result) basaltError(result)
end end

View File

@@ -1062,7 +1062,7 @@ local animTime = 0.2
local animFrames = 8 local animFrames = 8
local function download(url, file) local function download(url, file)
local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = token.." ".._G._GIT_API_KEY}) local httpReq = http.get(url, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
if(httpReq~=nil)then if(httpReq~=nil)then
local content = httpReq.readAll() local content = httpReq.readAll()
if not content then if not content then
@@ -1076,7 +1076,7 @@ end
local function createTree(page) local function createTree(page)
local tree = {} local tree = {}
local request = http.get(page, _G._GIT_API_KEY and {Authorization = basaltGithubToken.." ".._G._GIT_API_KEY}) local request = http.get(page, _G._GIT_API_KEY and {Authorization = "token ".._G._GIT_API_KEY})
if not(request)then return end if not(request)then return end
for k,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do for k,v in pairs(textutils.unserialiseJSON(request.readAll()).tree)do
if(v.type=="blob")then if(v.type=="blob")then

View File

@@ -171,8 +171,8 @@ end)
<button onClick="clickMe" text="Click me" /> <button onClick="clickMe" text="Click me" />
``` ```
## basalt.shedule ## basalt.schedule
Shedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits. Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
#### Parameters: #### Parameters:
1. `function` a function which should get executed 1. `function` a function which should get executed
@@ -181,11 +181,11 @@ Shedules a function which gets called in a coroutine. After the coroutine is fin
1. `function` it returns the function which you have to execute in order to start the coroutine 1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage: #### Usage:
* Creates a shedule which switches the color between red and gray * Creates a schedule which switches the color between red and gray
```lua ```lua
local mainFrame = basalt.createFrame() local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me") local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.shedule(function(self) aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red) self:setBackground(colors.red)
os.sleep(0.1) os.sleep(0.1)
self:setBackground(colors.gray) self:setBackground(colors.gray)