mirror of
https://github.com/kepler155c/opus
synced 2025-10-24 04:07:40 +00:00
transition to kernel
This commit is contained in:
@@ -127,6 +127,8 @@ local function getProxy(pi)
|
||||
error("Timed out attaching peripheral: " .. pi.uri)
|
||||
end
|
||||
|
||||
-- write the uri of the periperal we are requesting...
|
||||
-- ie. type/monitor
|
||||
socket:write(pi.path)
|
||||
local proxy = socket:read(3)
|
||||
|
||||
@@ -134,6 +136,10 @@ local function getProxy(pi)
|
||||
error("Timed out attaching peripheral: " .. pi.uri)
|
||||
end
|
||||
|
||||
if type(proxy) == 'string' then
|
||||
error(proxy)
|
||||
end
|
||||
|
||||
local methods = proxy.methods
|
||||
proxy.methods = nil
|
||||
|
||||
@@ -166,6 +172,9 @@ local function getProxy(pi)
|
||||
socket:read()
|
||||
end)
|
||||
end
|
||||
if not socket.connected then
|
||||
error("Timed out communicating with peripheral: " .. pi.uri)
|
||||
end
|
||||
|
||||
table.insert(queue, {
|
||||
fn = method,
|
||||
@@ -222,7 +231,7 @@ end
|
||||
function Peripheral.lookup(uri)
|
||||
local pi = parse(uri)
|
||||
|
||||
if pi.host then
|
||||
if pi.host and _G.device.wireless_modem then
|
||||
return getProxy(pi)
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ local os = _G.os
|
||||
local socketClass = { }
|
||||
|
||||
function socketClass:read(timeout)
|
||||
|
||||
local data, distance = _G.transport.read(self)
|
||||
if data then
|
||||
return data, distance
|
||||
@@ -31,6 +30,9 @@ function socketClass:read(timeout)
|
||||
os.cancelTimer(timerId)
|
||||
return data, distance
|
||||
end
|
||||
if not self.connected then
|
||||
break
|
||||
end
|
||||
|
||||
elseif e == 'timer' and id == timerId then
|
||||
if timeout or not self.connected then
|
||||
@@ -104,6 +106,9 @@ local function newSocket(isLoopback)
|
||||
end
|
||||
|
||||
function Socket.connect(host, port)
|
||||
if not device.wireless_modem then
|
||||
return false, 'Wireless modem not found'
|
||||
end
|
||||
|
||||
local socket = newSocket(host == os.getComputerID())
|
||||
socket.dhost = tonumber(host)
|
||||
@@ -149,7 +154,6 @@ function Socket.connect(host, port)
|
||||
end
|
||||
|
||||
local function trusted(msg, port)
|
||||
|
||||
if port == 19 or msg.shost == os.getComputerID() then
|
||||
-- no auth for trust server or loopback
|
||||
return true
|
||||
@@ -172,7 +176,6 @@ local function trusted(msg, port)
|
||||
end
|
||||
|
||||
function Socket.server(port)
|
||||
|
||||
device.wireless_modem.open(port)
|
||||
Logger.log('socket', 'Waiting for connections on port ' .. port)
|
||||
|
||||
|
||||
@@ -6,7 +6,40 @@ local _gsub = string.gsub
|
||||
|
||||
local Terminal = { }
|
||||
|
||||
function Terminal.scrollable(ct, size)
|
||||
function Terminal.scrollable(win, size)
|
||||
local w, h = win.getSize()
|
||||
local scrollPos = 0
|
||||
local scp = win.setCursorPos
|
||||
|
||||
win.setCursorPos = function(x, y)
|
||||
scp(x, y)
|
||||
if y > scrollPos + h then
|
||||
win.scrollTo(y - h)
|
||||
elseif y < scrollPos then
|
||||
win.scrollTo(y - 2)
|
||||
end
|
||||
end
|
||||
|
||||
win.scrollUp = function()
|
||||
win.scrollTo(scrollPos - 1)
|
||||
end
|
||||
|
||||
win.scrollDown = function()
|
||||
win.scrollTo(scrollPos + 1)
|
||||
end
|
||||
|
||||
win.scrollTo = function(p)
|
||||
p = math.min(math.max(p, 0), size)
|
||||
if p ~= scrollPos then
|
||||
scrollPos = p
|
||||
win.reposition(1, -scrollPos + 1, w, h + size)
|
||||
end
|
||||
end
|
||||
|
||||
win.reposition(1, 1, w, h + size, true)
|
||||
end
|
||||
|
||||
function Terminal.scrollable2(ct, size)
|
||||
|
||||
local w, h = ct.getSize()
|
||||
local win = _G.window.create(ct, 1, 1, w, h + size, true)
|
||||
@@ -63,7 +96,6 @@ function Terminal.scrollable(ct, size)
|
||||
|
||||
return win
|
||||
end
|
||||
|
||||
function Terminal.toGrayscale(ct)
|
||||
|
||||
local scolors = {
|
||||
|
||||
@@ -563,22 +563,23 @@ function Util.wordWrap(str, limit)
|
||||
end
|
||||
|
||||
function Util.args(arg)
|
||||
local tab = { remainder = { } }
|
||||
local options, args = { }, { }
|
||||
|
||||
local k = 1
|
||||
while k <= #arg do
|
||||
local v = arg[k]
|
||||
if string.sub(v, 1, 1) == '-' then
|
||||
local jopt = string.sub(v, 2)
|
||||
tab[ jopt ] = arg[ k + 1 ]
|
||||
local opt = string.sub(v, 2)
|
||||
options[opt] = arg[k + 1]
|
||||
k = k + 1
|
||||
else
|
||||
table.insert(tab.remainder, v)
|
||||
table.insert(args, v)
|
||||
end
|
||||
k = k + 1
|
||||
end
|
||||
return tab
|
||||
return options, args
|
||||
end
|
||||
|
||||
-- http://lua-users.org/wiki/AlternativeGetOpt
|
||||
local function getopt( arg, options )
|
||||
local tab = {}
|
||||
|
||||
Reference in New Issue
Block a user