e
This commit is contained in:
@@ -8,7 +8,7 @@ function object.getMachineEvent()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local event = INTERNAL_EVENT_QUEUE[1]
|
local event = INTERNAL_EVENT_QUEUE[1]
|
||||||
INTERNAL_EVENT_QUEUE[1]=nil
|
INTERNAL_EVENT_QUEUE={table.unpack(INTERNAL_EVENT_QUEUE, 2)}
|
||||||
return table.unpack(event)
|
return table.unpack(event)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ local fss = {}
|
|||||||
local object = {}
|
local object = {}
|
||||||
local uObject = {}
|
local uObject = {}
|
||||||
|
|
||||||
local function getFs(self)
|
local function getFs(disk)
|
||||||
return fss[tostring(self.__UDATA_id)]
|
return fss[tostring(disk.__UDATA_id)]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function normalize(path)
|
local function normalize(path)
|
||||||
@@ -75,23 +75,25 @@ end
|
|||||||
function uObject:readBytes(start, length)
|
function uObject:readBytes(start, length)
|
||||||
local f = getFs(self)
|
local f = getFs(self)
|
||||||
local file=fs.open(f, "r")
|
local file=fs.open(f, "r")
|
||||||
local data=fs.readAll()
|
local data=file.readAll()
|
||||||
file.close()
|
file.close()
|
||||||
return data:sub(start, start+length)
|
return data:sub(start+1, start+length)
|
||||||
end
|
end
|
||||||
|
|
||||||
function uObject:writeBytes(start, dat)
|
function uObject:writeBytes(start, dat)
|
||||||
local f = getFs(self)
|
local f = getFs(self)
|
||||||
local file=fs.open(f, "r")
|
local file=fs.open(f, "r")
|
||||||
local data=fs.readAll()
|
local data=file.readAll()
|
||||||
|
file.close()
|
||||||
|
file = fs.open(f, "w")
|
||||||
|
file.write(data:sub(1, start)..dat..data:sub(start+1+#dat, #data))
|
||||||
file.close()
|
file.close()
|
||||||
return data:sub(1, start)..dat..data:sub(start+#dat, #data)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function uObject:getSize()
|
function uObject:getSize()
|
||||||
local f = getFs(self)
|
local f = getFs(self)
|
||||||
local file=fs.open(f, "r")
|
local file=fs.open(f, "r")
|
||||||
local data=fs.readAll()
|
local data=file.readAll()
|
||||||
file.close()
|
file.close()
|
||||||
return #data
|
return #data
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
akeys = {}
|
||||||
|
akeys[keys.enter] = "\n"
|
||||||
|
akeys[keys.tab] = "\t"
|
||||||
|
akeys[keys.backspace] = "\b"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
local screen = {}
|
local screen = {}
|
||||||
|
|
||||||
local function write(sText)
|
function write(sText)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
local x, y = term.getCursorPos()
|
local x, y = term.getCursorPos()
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ local function write(sText)
|
|||||||
return nLinesPrinted
|
return nLinesPrinted
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.print(...)
|
function print(...)
|
||||||
local nLinesPrinted = 0
|
local nLinesPrinted = 0
|
||||||
local nLimit = select("#", ...)
|
local nLimit = select("#", ...)
|
||||||
for n = 1, nLimit do
|
for n = 1, nLimit do
|
||||||
@@ -69,7 +69,11 @@ function screen.print(...)
|
|||||||
nLinesPrinted = nLinesPrinted + write("\n")
|
nLinesPrinted = nLinesPrinted + write("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
function screen.printInline(...)
|
function screen.print(...)
|
||||||
|
print(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
function printInline(...)
|
||||||
local nLinesPrinted = 0
|
local nLinesPrinted = 0
|
||||||
local nLimit = select("#", ...)
|
local nLimit = select("#", ...)
|
||||||
for n = 1, nLimit do
|
for n = 1, nLimit do
|
||||||
@@ -77,8 +81,12 @@ function screen.printInline(...)
|
|||||||
nLinesPrinted = nLinesPrinted + write(s)
|
nLinesPrinted = nLinesPrinted + write(s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function screen.printInline(...)
|
||||||
|
printInline(...)
|
||||||
|
end
|
||||||
|
|
||||||
function screen.clear()
|
function screen.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
term.clear()
|
term.clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+44
-6
@@ -39,6 +39,13 @@ function string.split(str, delim, maxResultCountOrNil)
|
|||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _VG.sleep(nTime)
|
||||||
|
local timer = os.startTimer(nTime or 0)
|
||||||
|
repeat
|
||||||
|
local _, param = coroutine.yield("timer")
|
||||||
|
until param == timer
|
||||||
|
end
|
||||||
|
|
||||||
INTERNAL_DISKS={}
|
INTERNAL_DISKS={}
|
||||||
INTERNAL_SCREENS={}
|
INTERNAL_SCREENS={}
|
||||||
INTERNAL_NET={}
|
INTERNAL_NET={}
|
||||||
@@ -52,7 +59,7 @@ function addEventRaw(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function newComponent(type, object)
|
function newComponent(type, object)
|
||||||
local id = tostring(#INTERNAL_COMPONENT_REGESTRY+1)
|
local id = #INTERNAL_COMPONENT_REGESTRY+1
|
||||||
INTERNAL_COMPONENT_REGESTRY[id] = {type=type, object=object}
|
INTERNAL_COMPONENT_REGESTRY[id] = {type=type, object=object}
|
||||||
addEventRaw("componentAdded", type, object)
|
addEventRaw("componentAdded", type, object)
|
||||||
return {
|
return {
|
||||||
@@ -73,19 +80,23 @@ function _VG.component.list()
|
|||||||
local i = 0
|
local i = 0
|
||||||
return function()
|
return function()
|
||||||
i=i+1
|
i=i+1
|
||||||
return INTERNAL_COMPONENT_REGESTRY[tostring(i)].type, INTERNAL_COMPONENT_REGESTRY[tostring(i)].object
|
if INTERNAL_COMPONENT_REGESTRY[i] then
|
||||||
|
return INTERNAL_COMPONENT_REGESTRY[i]["type"], INTERNAL_COMPONENT_REGESTRY[i]["object"]
|
||||||
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function _VG.component.getFirst(type)
|
function _VG.component.getFirst(type)
|
||||||
local object={}
|
local object={}
|
||||||
for i,v in pairs(INTERNAL_COMPONENT_REGESTRY) do
|
for i,v in pairs(INTERNAL_COMPONENT_REGESTRY) do
|
||||||
if INTERNAL_COMPONENT_REGESTRY[tostring(i)].type == type then
|
if INTERNAL_COMPONENT_REGESTRY[i].type == type then
|
||||||
object=INTERNAL_COMPONENT_REGESTRY[tostring(i)]
|
object=INTERNAL_COMPONENT_REGESTRY[i]
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return object.object
|
return object["object"]
|
||||||
end
|
end
|
||||||
|
|
||||||
for i,v in ipairs(fs.list("/AceVM/components/")) do
|
for i,v in ipairs(fs.list("/AceVM/components/")) do
|
||||||
@@ -99,4 +110,31 @@ local file=fs.open("/computers/0/bios.lua","r")
|
|||||||
local bios=file.readAll()
|
local bios=file.readAll()
|
||||||
file.close()
|
file.close()
|
||||||
file=nil
|
file=nil
|
||||||
load(bios,"@bios",nil,_VG)()
|
local func = load(bios,"@bios",nil,_VG)
|
||||||
|
if not func then error("BIOS ERR") end
|
||||||
|
local BIOS_CORO = coroutine.create(func)
|
||||||
|
debug.sethook(BIOS_CORO, function() coroutine.yield("CC:TWEAKED", "CORO_TIMEOUT") end, "l", 20)
|
||||||
|
while true do
|
||||||
|
local ret = {coroutine.resume(BIOS_CORO)}
|
||||||
|
if ret[1] == false then
|
||||||
|
os.shutdown()
|
||||||
|
end
|
||||||
|
local timer = os.startTimer(0)
|
||||||
|
local exit = false
|
||||||
|
repeat
|
||||||
|
local event = {coroutine.yield()}
|
||||||
|
if event[1] == "timer" and event[2] == timer then
|
||||||
|
exit=true
|
||||||
|
elseif event[1]=="timer"or nil then
|
||||||
|
elseif event[1]=="key" then
|
||||||
|
addEventRaw("keyPressed", 1, event[2])
|
||||||
|
if akeys[event[2]] then
|
||||||
|
addEventRaw("keyTyped", 1, keys[event[2]])
|
||||||
|
end
|
||||||
|
elseif event[1]=="char" then
|
||||||
|
addEventRaw("keyTyped", 1, event[2])
|
||||||
|
elseif event[1]=="key_up" then
|
||||||
|
addEventRaw("keyReleased", 1, event[2])
|
||||||
|
end
|
||||||
|
until exit
|
||||||
|
end
|
||||||
+7
-12
@@ -1,13 +1,11 @@
|
|||||||
local disks={}
|
|
||||||
|
|
||||||
for i,v in component.list() do
|
|
||||||
if v.type == "udd" then
|
|
||||||
v.writeBytes(0,"Hello, World!")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--[[
|
|
||||||
local computer = component.getFirst("computer")
|
local computer = component.getFirst("computer")
|
||||||
local screen=component.getFirst("screen")
|
local screen=component.getFirst("screen")
|
||||||
|
while true do
|
||||||
|
local event = {computer.getMachineEvent()}
|
||||||
|
if event[1]~= nil then
|
||||||
|
screen.print(table.unpack(event))
|
||||||
|
end
|
||||||
|
end
|
||||||
if not screen then
|
if not screen then
|
||||||
local function e(...)end
|
local function e(...)end
|
||||||
screen = {
|
screen = {
|
||||||
@@ -158,7 +156,6 @@ local ok,err = xpcall(function()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep(0.02)
|
|
||||||
end
|
end
|
||||||
::invalid_boot::
|
::invalid_boot::
|
||||||
end
|
end
|
||||||
@@ -172,7 +169,6 @@ local ok,err = xpcall(function()
|
|||||||
computer.shutdown()
|
computer.shutdown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep(0.02)
|
|
||||||
end
|
end
|
||||||
end, debug.traceback)
|
end, debug.traceback)
|
||||||
if not ok then
|
if not ok then
|
||||||
@@ -187,12 +183,11 @@ if not ok then
|
|||||||
screen.print("Press enter to continue...")
|
screen.print("Press enter to continue...")
|
||||||
while true do
|
while true do
|
||||||
local event = {computer.getMachineEvent()}
|
local event = {computer.getMachineEvent()}
|
||||||
|
screen.print(table.unpack(event))
|
||||||
if event[1] == "keyTyped" then
|
if event[1] == "keyTyped" then
|
||||||
if event[3] == "\n" then
|
if event[3] == "\n" then
|
||||||
computer.shutdown()
|
computer.shutdown()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep(0.02)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]]
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
disks={1, 56}
|
disks={1,3,56}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
-- * `turtle.equip[Left|Right]`
|
-- * `turtle.equip[Left|Right]`
|
||||||
-- Licensed under the MIT license
|
-- Licensed under the MIT license
|
||||||
if _HOST:find("UnBIOS") then return end
|
if _HOST:find("UnBIOS") then return end
|
||||||
local keptAPIs = {bit32 = true, bit = true, ccemux = true, config = true, coroutine = true, debug = true, fs = true, http = true, mounter = true, os = true, periphemu = true, peripheral = true, redstone = true, rs = true, term = true, utf8 = true, _HOST = true, _CC_DEFAULT_SETTINGS = true, _CC_DISABLE_LUA51_FEATURES = true, _VERSION = true, assert = true, collectgarbage = true, error = true, gcinfo = true, getfenv = true, getmetatable = true, ipairs = true, __inext = true,load = true, loadstring = true, math = true, newproxy = true, next = true, pairs = true, pcall = true, rawequal = true, rawget = true, rawlen = true, rawset = true, select = true, setfenv = true, setmetatable = true, string = true, table = true, tonumber = true, tostring = true, type = true, unpack = true, xpcall = true, turtle = true, pocket = true, commands = true, _G = true, keys=true}
|
local keptAPIs = {keys=true, bit32 = true, bit = true, ccemux = true, config = true, coroutine = true, debug = true, fs = true, http = true, mounter = true, os = true, periphemu = true, peripheral = true, redstone = true, rs = true, term = true, utf8 = true, _HOST = true, _CC_DEFAULT_SETTINGS = true, _CC_DISABLE_LUA51_FEATURES = true, _VERSION = true, assert = true, collectgarbage = true, error = true, gcinfo = true, getfenv = true, getmetatable = true, ipairs = true, __inext = true,load = true, loadstring = true, math = true, newproxy = true, next = true, pairs = true, pcall = true, rawequal = true, rawget = true, rawlen = true, rawset = true, select = true, setfenv = true, setmetatable = true, string = true, table = true, tonumber = true, tostring = true, type = true, unpack = true, xpcall = true, turtle = true, pocket = true, commands = true, _G = true, keys=true}
|
||||||
local t = {}
|
local t = {}
|
||||||
for k in pairs(_G) do if not keptAPIs[k] then table.insert(t, k) end end
|
for k in pairs(_G) do if not keptAPIs[k] then table.insert(t, k) end end
|
||||||
for _,k in ipairs(t) do _G[k] = nil end
|
for _,k in ipairs(t) do _G[k] = nil end
|
||||||
|
|||||||
Reference in New Issue
Block a user