1
0
mirror of https://github.com/Adorable-Catgirl/Zorya-NEO.git synced 2024-11-14 14:38:04 +11:00
Zorya-NEO/mods/util_oefiv1/init.lua

58 lines
1.4 KiB
Lua
Raw Normal View History

2020-01-15 12:07:27 +11:00
local comp = component
local computer = computer
local thd = krequire("thd")
local zy = krequire("zorya")
local utils = krequire("utils")
local oefi = {}
local function load_oefi(drive, path, uuid)
local oefi_env = {}
2020-06-06 10:45:08 +10:00
local env = utils.make_env()
2020-01-15 12:07:27 +11:00
env.krequire = nil
env._BIOS = nil
env._ZVER = nil
env._ZVSTR = nil
env._ZPAT = nil
env.oefi = setmetatable(oefi_env, {__index=oefi})
function env.computer.getBootAddress()
return drive
end
function oefi_env.returnToOEFI()
computer.pushSignal("oefi_killall")
computer.pullSignal("k") --It actually kills the application
end
local h = comp.invoke(drive, "open", path)
local dat = utils.readfile(drive, h)
comp.invoke(drive, "close", h)
return load(dat, "="..path, "t", env)
end
function oefi.getAPIVersion()
return 1
end
function oefi.getImplementationName()
return _BIOS
end
function oefi.getImplementationVersion()
return _ZVER
end
function oefi.execOEFIApp(fs, path)
local uuid = string.char(math.random(0,255),math.random(0,255),math.random(0,255),math.random(0,255))
local func, manifest = load_oefi(drive, path, uuid)
local args = {}
local name = "oefi$"..manifest.name:gsub(" ", "_")
thd.add(name, function()
func(unpack(args))
os.pushSignal("oefi_end", uuid)
end) --ez
while true do
local s, i = computer.pullSignal()
if (s == "oefi_end" and i == uuid) or s == "oefi_killall" then
break
end
end
end