This commit is contained in:
2025-09-30 12:20:47 -04:00
parent 1a92ff1bd2
commit 91bf28a728
65 changed files with 2587 additions and 240 deletions

89
AceVM/components/Venv.lua Normal file
View File

@@ -0,0 +1,89 @@
local function deepcopy(orig, copies)
copies = copies or {}
if type(orig) ~= 'table' then
return orig
elseif copies[orig] then
return copies[orig]
end
local copy = {}
copies[orig] = copy
for k, v in next, orig, nil do
local copied_key = deepcopy(k, copies)
local copied_val = deepcopy(v, copies)
copy[copied_key] = copied_val
end
return copy
end
local _VG=deepcopy(_G)
local lua = {
coroutine = true,
debug = true,
_HOST = true,
_VERSION = true,
assert = true,
collectgarbage = true,
error = true,
gcinfo = true,
getfenv = true,
getmetatable = true,
ipairs = true,
__inext = true,
load = true,
math = 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,
xpcall = true
}
for i,v in pairs(_VG) do
if not lua[i] then
_VG[i]=nil
end
end
_VG._G=_VG
_VG.component={}
function _VG.component.list()
local i = 0
return function()
i=i+1
if aceVM.INTERNAL_COMPONENT_REGESTRY[i] then
return aceVM.INTERNAL_COMPONENT_REGESTRY[i]["type"], aceVM.INTERNAL_COMPONENT_REGESTRY[i]["object"]
else
return
end
end
end
function _VG.component.getFirst(type)
local object={}
for i,v in pairs(aceVM.INTERNAL_COMPONENT_REGESTRY) do
if aceVM.INTERNAL_COMPONENT_REGESTRY[i].type == type then
object=aceVM.INTERNAL_COMPONENT_REGESTRY[i]
break
end
end
return object["object"]
end
function aceVM.initVenv()
aceVM._VG = deepcopy(_VG)
end

View File

@@ -1,7 +1,5 @@
local object = {}
local file = fs.open("/computers/0/bios.lua", "r")
local bios = file.readAll()
file.close()
local bios = ""
function object.getData()
return bios
@@ -12,8 +10,14 @@ function object.setData(data)
end
function object.saveData()
local file=fs.open("/bios.lua", "w")
local file=fs.open("/AceVM/computers/"..tostring(aceVM.id).."/bios.lua", "w")
file.write(bios)
file.close()
end
newComponent("bios", object)
function aceVM.components.bios(id)
local file = fs.open("/AceVM/computers/"..tostring(id).."/bios.lua", "r")
bios = file.readAll()
file.close()
aceVM.newComponent("bios", object)
end

View File

@@ -1,7 +1,5 @@
local object = {}
local file = fs.open("/computers/0/nvram.dat", "r")
local nvram = string.split(file.readAll(), "\n")
file.close()
local nvram = {}
function object.getMachineEvent()
if INTERNAL_EVENT_QUEUE[1]==nil then
@@ -30,7 +28,7 @@ function object.setData(addr, data)
end
function object.saveData()
local file=fs.open("/nvram.dat", "w")
local file=fs.open("/AceVM/computers/"..tostring(aceVM.id).."/nvram.dat", "w")
file.write(table.concat(nvram,"\n"))
end
@@ -39,4 +37,9 @@ object.shutdown=os.shutdown
function object.beep() end -- IDK how i should implement this
newComponent("computer", object)
function aceVM.components.computer(id)
local file = fs.open("/AceVM/computers/"..tostring(id).."/nvram.dat", "r")
nvram = string.split(file.readAll(), "\n")
file.close()
aceVM.newComponent("computer", object)
end

View File

@@ -1,3 +1,4 @@
local fss = {}
local object = {}
local uObject = {}
@@ -119,42 +120,37 @@ function uObject:getSize()
return #data
end
local function findDisks(tble)
function aceVM.initDisks(tble)
for i,v in ipairs(tble) do
if fs.exists("/disks/"..tostring(v).."h") then
if fs.exists("/AceVM/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
aceVM.newComponent("disk", obj)
fss[tostring(v)]="/AceVM/disks/"..tostring(v).."h/"
elseif fs.exists("/AceVM/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
aceVM.newComponent("disk", obj)
fss[tostring(v)]="/AceVM/disks/"..tostring(v).."f/"
elseif fs.exists("/AceVM/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"
aceVM.newComponent("disk", obj)
fss[tostring(v)]="/AceVM/disks/"..tostring(v).."u"
else
fs.makeDir("/disks/"..tostring(v).."f/")
fs.makeDir("/AceVM/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/"
aceVM.newComponent("disk", obj)
fss[tostring(v)]="/AceVM/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)
end

View File

@@ -1,28 +1,7 @@
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
function internet.get(url) return http.get(url).readAll() 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)
function aceVM.components.internet(id)
aceVM.newComponent("internet", internet)
end

View File

@@ -1,4 +0,0 @@
akeys = {}
akeys[keys.enter] = "\n"
akeys[keys.tab] = "\t"
akeys[keys.backspace] = "\b"

View File

@@ -1,90 +1,13 @@
local screen = {}
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 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")
function screen.printInline(...)
term.write(table.concat({...}, " "))
end
function screen.print(...)
print(...)
end
function 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.printInline(...)
printInline(...)
end
function screen.clear()
term.setCursorPos(1,1)
term.clear()
@@ -93,4 +16,6 @@ end
screen.id = "screen_1"
screen.__UDATA_ID = 1
newComponent("screen", screen)
function aceVM.components.screen(id)
aceVM.newComponent("screen", screen)
end