diff --git a/465436f3-f424-4ca2-a70d-880542e28bc5/init.lua b/465436f3-f424-4ca2-a70d-880542e28bc5/init.lua index 34cd4c5..64c1651 100644 --- a/465436f3-f424-4ca2-a70d-880542e28bc5/init.lua +++ b/465436f3-f424-4ca2-a70d-880542e28bc5/init.lua @@ -27,6 +27,7 @@ do function rom.close(handle) return rom.invoke("close", handle) end function rom.inits() return ipairs(rom.invoke("list", "boot")) end function rom.isDirectory(path) return rom.invoke("isDirectory", path) end + function rom.exists(path) return rom.invoke("exists", path) end local screen = component.list('screen', true)() for address in component.list('screen', true) do @@ -62,8 +63,7 @@ do status("Booting " .. _OSVERSION .. "...") -- Custom low-level loadfile/dofile implementation reading from our ROM. - local function loadfile(file) - status("> " .. file) + local function readfile(file) local handle, reason = rom.open(file) if not handle then error(reason) @@ -77,7 +77,12 @@ do buffer = buffer .. (data or "") until not data rom.close(handle) - return load(buffer, "=" .. file) + return buffer + end + + local function loadfile(file) + status("> " .. file) + return load(readfile(file), "=" .. file) end local function dofile(file) @@ -146,9 +151,17 @@ do status("Initializing components...") local primaries = {} + local desiredPrimaries = {} + if rom.exists('/etc/components.cfg') then + local unserialize = require('serialization').unserialize + desiredPrimaries = unserialize(readfile('/etc/components.cfg')) + end for c, t in component.list() do local s = component.slot(c) - if not primaries[t] or (s >= 0 and s < primaries[t].slot) then + if (not primaries[t] + or (s >= 0 and s < primaries[t].slot) + or (desiredPrimaries[t] and c:match('^' .. desiredPrimaries[t]))) + then primaries[t] = {address=c, slot=s} end computer.pushSignal("component_added", c, t)