function one()
print("one")
end
function two()
print("two")
end
one()
two()
Function two will not run until function one has completed. os.run doesn't add into a top level, it runs the supplied file.
This is the os.run implementation ( bad indentation by developers FTW! :P/> )
-- Install the rest of the OS api
function os.run( _tEnv, _sPath, ... )
local tArgs = { ... }
local fnFile, err = loadfile( _sPath )
if fnFile then
local tEnv = _tEnv
--setmetatable( tEnv, { __index = function(t,k) return _G[k] end } )
setmetatable( tEnv, { __index = _G } )
setfenv( fnFile, tEnv )
local ok, err = pcall( function()
fnFile( unpack( tArgs ) )
end )
if not ok then
if err and err ~= "" then
printError( err )
end
return false
end
return true
end
if err and err ~= "" then
printError( err )
end
return false
end
This is why they do this for when running their shell and rednet.
-- Run the shell
local ok, err = pcall( function()
parallel.waitForAny(
function()
os.run( {}, "rom/programs/shell" )
end,
function()
rednet.run()
end )
end )
Try this code
local initf = fs.list("/.melted/init")
for i = 1, #initf do
initf[i] = function() os.run({["print"] = iprint}, fs.combine("/.melted/init/", initf[i])) end
end
parallel.waitForAll( unpack(initf) )