moved post-library init code to extra file

This commit is contained in:
Florian Nücke 2013-11-27 18:34:49 +01:00
parent 7d4f4c46f3
commit 453be0f2f5
2 changed files with 23 additions and 19 deletions

View File

@ -227,8 +227,10 @@ sandbox = {
-------------------------------------------------------------------------------
-- Start of non-standard stuff.
address = os.address,
isRobot = os.isRobot,
address = os.address,
romAddress = os.romAddress,
tmpAddress = os.tmpAddress,
freeMemory = os.freeMemory,
totalMemory = os.totalMemory,
uptime = os.uptime,
@ -346,9 +348,7 @@ local function main()
local buffer = ""
repeat
local data = rom.read(handle)
if data then
buffer = buffer .. data
end
buffer = buffer .. (data or "")
until not data
rom.close(handle)
local program, reason = load(buffer, "=" .. file, "t", sandbox)
@ -357,10 +357,10 @@ local function main()
if result[1] then
return table.unpack(result, 2, result.n)
else
error("error initializing lib: " .. result[2])
error(result[2])
end
else
error("error loading lib: " .. reason)
error(reason)
end
end
end
@ -383,19 +383,7 @@ local function main()
-- Yield once to get a memory baseline.
coroutine.yield()
return coroutine.create(load(string.format([[
fs.mount("%s", "/")
fs.mount("%s", "/tmp")
for c, t in component.list() do
os.pushSignal("component_added", c, t)
end
term.clear()
while true do
local result, reason = os.execute("/bin/sh -v")
if not result then
print(reason)
end
end]], os.romAddress(), os.tmpAddress()), "=init", "t", sandbox))
return coroutine.create(function() dofile("/init.lua") end)
end
local co, args = bootstrap(), {n=0}
while true do

View File

@ -0,0 +1,16 @@
fs.mount(os.romAddress(), "/")
fs.mount(os.tmpAddress(), "/tmp")
for c, t in component.list() do
os.pushSignal("component_added", c, t)
end
os.sleep(0.5) -- Allow signal processing by libraries.
term.clear()
while true do
local result, reason = os.execute("/bin/sh -v")
if not result then
print(reason)
end
end