e
This commit is contained in:
@@ -0,0 +1 @@
|
||||
local object = {}
|
||||
@@ -0,0 +1,19 @@
|
||||
local object = {}
|
||||
local file = fs.open("/computers/0/bios.lua", "r")
|
||||
local bios = file.readAll()
|
||||
file.close()
|
||||
|
||||
function object.getData()
|
||||
return bios
|
||||
end
|
||||
|
||||
function object.setData(data)
|
||||
bios=data
|
||||
end
|
||||
|
||||
function object.saveData()
|
||||
local file=fs.open("/bios.lua", "w")
|
||||
file.write(bios)
|
||||
end
|
||||
|
||||
newComponent("bios", object)
|
||||
@@ -0,0 +1,42 @@
|
||||
local object = {}
|
||||
local file = fs.open("/computers/0/nvram.dat", "r")
|
||||
local nvram = string.split(file.readAll(), "\n")
|
||||
file.close()
|
||||
|
||||
function object.getMachineEvent()
|
||||
if INTERNAL_EVENT_QUEUE[1]==nil then
|
||||
return nil
|
||||
end
|
||||
local event = INTERNAL_EVENT_QUEUE[1]
|
||||
INTERNAL_EVENT_QUEUE[1]=nil
|
||||
return table.unpack(event)
|
||||
end
|
||||
|
||||
function object.getData(addr)
|
||||
if type(addr)~="number" then
|
||||
error()
|
||||
end
|
||||
return nvram[addr]
|
||||
end
|
||||
|
||||
function object.setData(addr, data)
|
||||
if type(addr)~="number" then
|
||||
error()
|
||||
end
|
||||
if type(data)~="string" then
|
||||
error()
|
||||
end
|
||||
nvram[addr]=data
|
||||
end
|
||||
|
||||
function object.saveData()
|
||||
local file=fs.open("/nvram.dat", "w")
|
||||
file.write(table.concat(nvram,"\n"))
|
||||
end
|
||||
|
||||
object.reboot=os.reboot
|
||||
object.shutdown=os.shutdown
|
||||
|
||||
function object.beep() end -- IDK how i should implement this
|
||||
|
||||
newComponent("computer", object)
|
||||
@@ -0,0 +1,137 @@
|
||||
local fss = {}
|
||||
local object = {}
|
||||
local uObject = {}
|
||||
|
||||
local function getFs(self)
|
||||
return fss[tostring(self.__UDATA_id)]
|
||||
end
|
||||
|
||||
local function normalize(path)
|
||||
if path:sub(1,1)=="/" then
|
||||
path=path:sub(2)
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
function object:open(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
return {
|
||||
read=function()
|
||||
local file = fs.open(f..path, "r")
|
||||
local text = file.readAll()
|
||||
file.close()
|
||||
return text
|
||||
end,
|
||||
write=function(text)
|
||||
local file = fs.open(f..path, "w")
|
||||
file.write(text)
|
||||
file.close()
|
||||
end,
|
||||
append=function(text)
|
||||
local file = fs.open(f..path, "a")
|
||||
file.write(text)
|
||||
file.close()
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
function object:list(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
return fs.list(f..path)
|
||||
end
|
||||
|
||||
function object:fileExists(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
return fs.exists(f..path) and not fs.isDir(f..path)
|
||||
end
|
||||
|
||||
function object:directoryExists(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
return fs.exists(f..path) and fs.isDir(f..path)
|
||||
end
|
||||
|
||||
function object:makeDirectory(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
fs.makeDir(f..path)
|
||||
end
|
||||
|
||||
function object:delete(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
fs.delete(f..path)
|
||||
end
|
||||
|
||||
function object:getSize(path)
|
||||
path=normalize(path)
|
||||
local f = getFs(self)
|
||||
return fs.getSize(f..path)
|
||||
end
|
||||
|
||||
function uObject:readBytes(start, length)
|
||||
local f = getFs(self)
|
||||
local file=fs.open(f, "r")
|
||||
local data=fs.readAll()
|
||||
file.close()
|
||||
return data:sub(start, start+length)
|
||||
end
|
||||
|
||||
function uObject:writeBytes(start, dat)
|
||||
local f = getFs(self)
|
||||
local file=fs.open(f, "r")
|
||||
local data=fs.readAll()
|
||||
file.close()
|
||||
return data:sub(1, start)..dat..data:sub(start+#dat, #data)
|
||||
end
|
||||
|
||||
function uObject:getSize()
|
||||
local f = getFs(self)
|
||||
local file=fs.open(f, "r")
|
||||
local data=fs.readAll()
|
||||
file.close()
|
||||
return #data
|
||||
end
|
||||
|
||||
local function findDisks(tble)
|
||||
for i,v in ipairs(tble) do
|
||||
if fs.exists("/disks/"..tostring(v).."h") then
|
||||
local obj = deepcopy(object)
|
||||
obj.__UDATA_id=v
|
||||
obj.id="disk_"..tostring(v)
|
||||
obj.type="hdd"
|
||||
newComponent("disk", obj)
|
||||
fss[tostring(v)]="/disks/"..tostring(v).."h/"
|
||||
elseif fs.exists("/disks/"..tostring(v).."f") then
|
||||
local obj = deepcopy(object)
|
||||
obj.__UDATA_id=v
|
||||
obj.id="disk_"..tostring(v)
|
||||
obj.type="fdd"
|
||||
newComponent("disk", obj)
|
||||
fss[tostring(v)]="/disks/"..tostring(v).."f/"
|
||||
elseif fs.exists("/disks/"..tostring(v).."u") then
|
||||
local obj = deepcopy(uObject)
|
||||
obj.__UDATA_id=v
|
||||
obj.id="disk_"..tostring(v)
|
||||
obj.type="udd"
|
||||
newComponent("disk", obj)
|
||||
fss[tostring(v)]="/disks/"..tostring(v).."u"
|
||||
else
|
||||
fs.makeDir("/disks/"..tostring(v).."f/")
|
||||
local obj = deepcopy(object)
|
||||
obj.__UDATA_id=v
|
||||
obj.id="disk_"..tostring(v)
|
||||
obj.type="fdd"
|
||||
newComponent("disk", obj)
|
||||
fss[tostring(v)]="/disks/"..tostring(v).."f/"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local file = fs.open("/computers/0/computer.ltable", "r")
|
||||
local config = load("return "..file.readAll())()
|
||||
file.close()
|
||||
findDisks(config.disks)
|
||||
@@ -0,0 +1,28 @@
|
||||
local internet = {}
|
||||
|
||||
local function wrap_request(_url, ...)
|
||||
local ok, err = http.request(...)
|
||||
if ok then
|
||||
while true do
|
||||
local event, param1, param2, param3 = coroutine.yield()
|
||||
if event == "http_success" and param1 == _url then
|
||||
return param2
|
||||
elseif event == "http_failure" and param1 == _url then
|
||||
return nil, param2, param3
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local function get(_url)
|
||||
if type(_url) ~= "string" then
|
||||
error("URL must be a string")
|
||||
end
|
||||
|
||||
return wrap_request(_url, _url)
|
||||
end
|
||||
|
||||
function internet.get(url) return get(url).readAll() end
|
||||
|
||||
newComponent("internet", internet)
|
||||
@@ -0,0 +1,88 @@
|
||||
local screen = {}
|
||||
|
||||
local function write(sText)
|
||||
local w, h = term.getSize()
|
||||
local x, y = term.getCursorPos()
|
||||
|
||||
local nLinesPrinted = 0
|
||||
local function newLine()
|
||||
if y + 1 <= h then
|
||||
term.setCursorPos(1, y + 1)
|
||||
else
|
||||
term.setCursorPos(1, h)
|
||||
term.scroll(1)
|
||||
end
|
||||
x, y = term.getCursorPos()
|
||||
nLinesPrinted = nLinesPrinted + 1
|
||||
end
|
||||
|
||||
sText = tostring(sText)
|
||||
while #sText > 0 do
|
||||
local whitespace = string.match(sText, "^[ \t]+")
|
||||
if whitespace then
|
||||
term.write(whitespace)
|
||||
x, y = term.getCursorPos()
|
||||
sText = string.sub(sText, #whitespace + 1)
|
||||
end
|
||||
|
||||
local newline = string.match(sText, "^\n")
|
||||
if newline then
|
||||
newLine()
|
||||
sText = string.sub(sText, 2)
|
||||
end
|
||||
|
||||
local text = string.match(sText, "^[^ \t\n]+")
|
||||
if text then
|
||||
sText = string.sub(sText, #text + 1)
|
||||
if #text > w then
|
||||
while #text > 0 do
|
||||
if x > w then
|
||||
newLine()
|
||||
end
|
||||
term.write(text)
|
||||
text = string.sub(text, w - x + 2)
|
||||
x, y = term.getCursorPos()
|
||||
end
|
||||
else
|
||||
if x + #text - 1 > w then
|
||||
newLine()
|
||||
end
|
||||
term.write(text)
|
||||
x, y = term.getCursorPos()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nLinesPrinted
|
||||
end
|
||||
|
||||
function screen.print(...)
|
||||
local nLinesPrinted = 0
|
||||
local nLimit = select("#", ...)
|
||||
for n = 1, nLimit do
|
||||
local s = tostring(select(n, ...))
|
||||
if n < nLimit then
|
||||
s = s .. "\t"
|
||||
end
|
||||
nLinesPrinted = nLinesPrinted + write(s)
|
||||
end
|
||||
nLinesPrinted = nLinesPrinted + write("\n")
|
||||
end
|
||||
|
||||
function screen.printInline(...)
|
||||
local nLinesPrinted = 0
|
||||
local nLimit = select("#", ...)
|
||||
for n = 1, nLimit do
|
||||
local s = tostring(select(n, ...))
|
||||
nLinesPrinted = nLinesPrinted + write(s)
|
||||
end
|
||||
end
|
||||
|
||||
function screen.clear()
|
||||
term.clear()
|
||||
end
|
||||
|
||||
screen.id = "screen_1"
|
||||
screen.__UDATA_ID = 1
|
||||
|
||||
newComponent("screen", screen)
|
||||
Reference in New Issue
Block a user