From 67789cccae3b8531462e057b4643f3337c56632f Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 31 Jul 2017 12:10:24 +1000 Subject: [PATCH] also ported the MultICE io API --- modules/lib/io.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 modules/lib/io.lua diff --git a/modules/lib/io.lua b/modules/lib/io.lua new file mode 100644 index 0000000..d893dcf --- /dev/null +++ b/modules/lib/io.lua @@ -0,0 +1,35 @@ +-- not gonna lie, this was just ported from MultICE. Code is terrible and I should rewrite it. +_G.io = {} +io.write = write +function io.open(n,m) + m=m or "rb" + local h=fs.open(n,m) + if h then + if h and m:sub(1,1) == "w" then + return buffer.create(function(bt) + bt.s="o" + spawn("io worker: "..n,function() + while true do + if bt.s ~= "o" and bt.b == "" then fclose(h) break end + local nd = bt:read(2048) + if nd ~= nil and nd ~= "" then + fs.write(h,nd) + end + coroutine.yield() + end + end) end,function(bt) bt.s="c" end) + elseif h and m:sub(1,1) == "r" then + return buffer.create(function(bt) + local sb = "" + repeat + bt.b=bt.b..sb + sb=fs.read(h,2048) + until sb == "" or sb == nil + fs.close(h) + coroutine.yield() + end,function() end) + end + else + return false + end +end