From ead102f131922816023bfbb48ac1ea22a261be64 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sun, 28 Jul 2019 12:45:38 +1000 Subject: [PATCH] made the shell spawn executed files as their own process and wait for them to complete --- exec/shell.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exec/shell.lua b/exec/shell.lua index 9a137b9..a0facd1 100644 --- a/exec/shell.lua +++ b/exec/shell.lua @@ -3,7 +3,19 @@ local shenv = {} function shenv.quit() os.setenv("run",nil) end -setmetatable(shenv,{__index=function(_,k) if _G[k] then return _G[k] elseif fs.exists("/boot/exec/"..k..".lua") then return loadfile("/boot/exec/"..k..".lua") end end}) +setmetatable(shenv,{__index=function(_,k) + if _G[k] then + return _G[k] + elseif fs.exists("/boot/exec/"..k..".lua") then + return function(...) + local tA = {...} + local pid = os.spawn(function() loadfile("/boot/exec/"..k..".lua")(table.unpack(tA)) end,"/boot/exec/"..k..".lua") + repeat + coroutine.yield() + until tTasks[pid] == nil + end + end +end}) print(_VERSION) os.setenv("run",true) while os.getenv("run") do