Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a=http.get"https://raw.githubusercontent.com/osmarks/skynet/master/client.lua"local b=fs.open("skynet","w")b.write(a.readAll())a.close()b.close()
- local skynet = require "./skynet"
- local term_mutation_functions = {
- "blit",
- "setCursorPos",
- "write",
- "clear",
- "clearLine",
- "setCursorBlink",
- "scroll",
- "setTextColor",
- "setBackgroundColor"
- }
- local txqueue = { ref = {} }
- local function make_transmitting_term(realterm, callback)
- local newterm = {}
- for name in pairs(term) do
- local realfunc = realterm[name]
- newterm[name] = function(...)
- return realfunc(...)
- end
- end
- for _, fname in pairs(term_mutation_functions) do
- local real_function = realterm[fname]
- newterm[fname] = function(...)
- callback(fname, {...})
- local results = {real_function(...)}
- return table.unpack(results)
- end
- end
- function newterm.isColor() return true end
- return newterm
- end
- local channel, program = ...
- if not channel then error "First argument must be skynet channel to use!" end
- if tonumber(channel) then channel = tonumber(channel) end
- local function skynet_transmit_callback(fun, args)
- table.insert(txqueue.ref, {fun, args})
- os.queueEvent "txqueue_insert"
- end
- local function skynet_listener()
- while true do
- local _, msg = skynet.receive(channel)
- if type(msg) == "table" then
- if msg.type == "event" and msg.event then
- os.queueEvent(table.unpack(msg.event))
- elseif msg.type == "ping" then
- skynet.send(channel, { type = "pong" })
- end
- end
- end
- end
- local function txqueue_sender()
- while true do
- if #txqueue.ref > 0 then
- skynet.send(channel, { type = "term calls", calls = txqueue.ref })
- txqueue.ref = {}
- end
- sleep(0.05)
- end
- end
- local newterm = make_transmitting_term(term.native(), skynet_transmit_callback)
- local oldterm = term.redirect(newterm)
- parallel.waitForAll(txqueue_sender, skynet_listener, function()
- term.clear()
- term.setCursorPos(1, 1)
- print "Terminal Link Established"
- shell.run "shell"
- end)
- term.redirect(oldterm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement