LuPPC/src/lua/core/init.lua

91 lines
2.1 KiB
Lua
Raw Normal View History

2016-01-07 02:58:05 +11:00
function checkArg(n, have, ...)
2016-01-06 08:29:49 +11:00
have = type(have)
local function check(want, ...)
if not want then
return false
else
return have == want or check(...)
end
end
if not check(...) then
local msg = string.format("bad argument #%d (%s expected, got %s)",
n, table.concat({...}, " or "), have)
error(msg, 3)
end
end
-------------------------------------------------------------------------------
2016-01-14 12:13:00 +11:00
math.randomseed(native.uptime())--TODO: Make it better?
2016-01-06 08:29:49 +11:00
2016-01-05 04:20:40 +11:00
print("LuPI L1 INIT")
modules = {}
2016-01-10 05:39:48 +11:00
deadhooks = {}
2016-01-05 04:20:40 +11:00
local function loadModule(name)
print("LuPI L1 INIT > Load module > " .. name)
2016-01-14 11:10:04 +11:00
io.flush()
2016-01-05 04:20:40 +11:00
--TODO: PRERELEASE: Module sandboxing, preferably secure-ish
--TODO: ASAP: Handle load errors
if not moduleCode[name] then
error("No code for module " .. tostring(name))
end
2016-01-10 05:39:48 +11:00
local code, reason = load(moduleCode[name], "=Module "..name)
2016-01-06 08:29:49 +11:00
if not code then
print("Failed loading module " .. name .. ": " .. reason)
2016-01-14 11:10:04 +11:00
io.flush()
2016-01-06 08:29:49 +11:00
else
modules[name] = code()
end
2016-01-05 04:20:40 +11:00
end
2016-01-10 05:39:48 +11:00
function main()
--Load modules
--Utils
loadModule("random")
loadModule("color")
2016-01-14 11:10:04 +11:00
loadModule("utf8data")
loadModule("utf8")
2016-01-07 02:58:05 +11:00
2016-01-14 12:13:00 +11:00
modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
2016-01-10 05:39:48 +11:00
--Core
loadModule("component")
loadModule("computer")
2016-01-07 02:58:05 +11:00
2016-01-10 05:39:48 +11:00
--Components
loadModule("eeprom")
loadModule("textgpu")
loadModule("filesystem")
2016-01-07 02:58:05 +11:00
2016-01-10 05:39:48 +11:00
--Userspace
loadModule("sandbox")
loadModule("boot")
2016-01-05 04:20:40 +11:00
2016-01-10 05:39:48 +11:00
--Setup core modules
modules.component.prepare()
modules.computer.prepare()
2016-01-15 08:44:49 +11:00
_G.pushEvent = modules.computer.api.pushSignal
2016-01-05 04:20:40 +11:00
2016-01-10 05:39:48 +11:00
modules.eeprom.register()
modules.filesystem.register("root")
2016-01-19 06:29:05 +11:00
modules.filesystem.register("/") --TODO: remove from release
2016-01-20 04:25:09 +11:00
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
2016-01-10 05:39:48 +11:00
modules.textgpu.start()
2016-01-07 07:32:53 +11:00
2016-01-10 05:39:48 +11:00
modules.boot.boot()
end
local state, cause = pcall(main)
if not state then
print("LuPI finished with following error:")
print(cause)
end
print("Running shutdown hooks")
for k, hook in ipairs(deadhooks) do
local state, cause = pcall(hook)
if not state then
print("Shutdown hook with following error:")
print(cause)
end
end