opus/sys/boot/opus.lua

59 lines
1.3 KiB
Lua
Raw Normal View History

2019-06-29 06:44:30 +00:00
local fs = _G.fs
2017-09-26 02:49:44 +00:00
-- override bios function to use the global scope of the current env
function _G.loadstring(string, chunkname)
return load(string, chunkname, nil, getfenv(2)._G)
end
2020-05-24 03:45:05 +00:00
-- override bios function to include the actual filename
2020-05-29 04:54:48 +00:00
function _G.loadfile(filename, mode, env)
2020-05-24 03:45:05 +00:00
-- Support the previous `loadfile(filename, env)` form instead.
if type(mode) == "table" and env == nil then
mode, env = nil, mode
end
local file = fs.open(filename, "r")
if not file then return nil, "File not found" end
local func, err = load(file.readAll(), '@' .. filename, mode, env)
file.close()
return func, err
end
2017-10-20 08:23:17 +00:00
local sandboxEnv = setmetatable({ }, { __index = _G })
for k,v in pairs(_ENV) do
2018-01-24 22:39:38 +00:00
sandboxEnv[k] = v
2017-10-20 08:23:17 +00:00
end
2018-01-13 20:17:26 +00:00
-- Install require shim
_G.requireInjector = loadfile('sys/modules/opus/injector.lua', _ENV)()
2019-06-29 06:44:30 +00:00
local function run(file, ...)
2018-01-24 22:39:38 +00:00
local env = setmetatable({ }, { __index = _G })
for k,v in pairs(sandboxEnv) do
env[k] = v
end
2016-12-11 19:24:52 +00:00
_G.requireInjector(env)
2019-06-29 06:44:30 +00:00
local s, m = loadfile(file, env)
2018-01-24 22:39:38 +00:00
if s then
return s(...)
end
error('Error loading ' .. file .. '\n' .. m)
2016-12-11 19:24:52 +00:00
end
2019-06-29 06:44:30 +00:00
_G._syslog = function() end
_G.OPUS_BRANCH = 'develop-1.8'
2017-09-26 02:49:44 +00:00
2019-02-12 22:03:50 +00:00
local s, m = pcall(run, 'sys/apps/shell.lua', 'sys/kernel.lua', ...)
2018-01-12 01:53:32 +00:00
if not s then
2018-01-24 22:39:38 +00:00
print('\nError loading Opus OS\n')
_G.printError(m .. '\n')
2018-01-12 01:53:32 +00:00
end
2017-09-26 02:49:44 +00:00
2018-01-13 20:17:26 +00:00
if fs.restore then
2018-01-24 22:39:38 +00:00
fs.restore()
2018-01-13 20:17:26 +00:00
end