diff --git a/sys/apis/fs/netfs.lua b/sys/apis/fs/netfs.lua index 58089a4..d7eb2eb 100644 --- a/sys/apis/fs/netfs.lua +++ b/sys/apis/fs/netfs.lua @@ -1,5 +1,5 @@ local Socket = require('socket') -local synchronized = require('sync') +local synchronized = require('sync').sync local fs = _G.fs diff --git a/sys/apis/sync.lua b/sys/apis/sync.lua index e0b841e..7987cb4 100644 --- a/sys/apis/sync.lua +++ b/sys/apis/sync.lua @@ -1,26 +1,61 @@ -local syncLocks = { } +local Sync = { + syncLocks = { } +} local os = _G.os -return function(obj, fn) +function Sync.sync(obj, fn) local key = tostring(obj) - if syncLocks[key] then + if Sync.syncLocks[key] then local cos = tostring(coroutine.running()) - table.insert(syncLocks[key], cos) + table.insert(Sync.syncLocks[key], cos) repeat local _, co = os.pullEvent('sync_lock') until co == cos else - syncLocks[key] = { } + Sync.syncLocks[key] = { } end local s, m = pcall(fn) - local co = table.remove(syncLocks[key], 1) + local co = table.remove(Sync.syncLocks[key], 1) if co then os.queueEvent('sync_lock', co) else - syncLocks[key] = nil + Sync.syncLocks[key] = nil end if not s then error(m) end end + +function Sync.lock(obj) + local key = tostring(obj) + if Sync.syncLocks[key] then + local cos = tostring(coroutine.running()) + table.insert(Sync.syncLocks[key], cos) + repeat + local _, co = os.pullEvent('sync_lock') + until co == cos + else + Sync.syncLocks[key] = { } + end +end + +function Sync.release(obj) + local key = tostring(obj) + if not Sync.syncLocks[key] then + error('Sync.release: Lock was not obtained', 2) + end + local co = table.remove(Sync.syncLocks[key], 1) + if co then + os.queueEvent('sync_lock', co) + else + Sync.syncLocks[key] = nil + end +end + +function Sync.isLocked(obj) + local key = tostring(obj) + return not not Sync.syncLocks[key] +end + +return Sync diff --git a/sys/apis/ui.lua b/sys/apis/ui.lua index ead3543..fbc3f5c 100644 --- a/sys/apis/ui.lua +++ b/sys/apis/ui.lua @@ -2959,6 +2959,7 @@ UI.Chooser.defaults = { choices = { }, nochoice = 'Select', backgroundFocusColor = colors.lightGray, + textInactiveColor = colors.gray, leftIndicator = '<', rightIndicator = '>', height = 1, @@ -2981,13 +2982,14 @@ function UI.Chooser:draw() if self.focused then bg = self.backgroundFocusColor end + local fg = self.inactive and self.textInactiveColor or self.textColor local choice = Util.find(self.choices, 'value', self.value) local value = self.nochoice if choice then value = choice.name end self:write(1, 1, self.leftIndicator, self.backgroundColor, colors.black) - self:write(2, 1, ' ' .. Util.widthify(tostring(value), self.width-4) .. ' ', bg) + self:write(2, 1, ' ' .. Util.widthify(tostring(value), self.width-4) .. ' ', bg, fg) self:write(self.width, 1, self.rightIndicator, self.backgroundColor, colors.black) end diff --git a/sys/extensions/6.tl3.lua b/sys/extensions/6.tl3.lua index 3985dcf..d82930a 100644 --- a/sys/extensions/6.tl3.lua +++ b/sys/extensions/6.tl3.lua @@ -7,7 +7,7 @@ _G.requireInjector(_ENV) local Pathing = require('turtle.pathfind') local GPS = require('gps') local Point = require('point') -local synchronized = require('sync') +local synchronized = require('sync').sync local Util = require('util') local os = _G.os diff --git a/sys/kernel.lua b/sys/kernel.lua index b130204..b686bd8 100644 --- a/sys/kernel.lua +++ b/sys/kernel.lua @@ -34,6 +34,12 @@ _G._debug = function(pattern, ...) term.redirect(oldTerm) end +if not _G.debug then -- don't clobber lua debugger + function _G.debug(...) + _G._debug(...) + end +end + -- any function that runs in a kernel hook does not run in -- a separate coroutine or have a window. an error in a hook -- function will crash the system.