Advertisement
Piorjade

Top Level Coroutine Override FIXED/REWORKED

Sep 16th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. --[[
  2.     Attempt to recreate Top-Level coroutines
  3.     Because the old program doesn't work (for me atleast)
  4.    
  5.     UPDATE: This is Lua 5.2+ compatible now
  6.    
  7.     Credits to:
  8.     -Nevercast (for the old script, of course)
  9.     -Me (kappa)
  10.    
  11.     Have fun with this :)
  12.    
  13.     Nevercast's code: http://pastebin.com/2SQAzrWi
  14.    
  15.     The problem was the way he searched for shell. I already fixed it ones but Lua 5.2+ won't have getfenv()
  16.     anymore and that's why I give a even smaller version of it
  17.    
  18.     And thanks (again) to Nevercast for this awesome idea :)
  19.    
  20.     -Piorjade 2016
  21. ]]
  22.  
  23. local progs = {
  24.     function()
  25.         print("Before shell.")
  26.         os.run( {}, "rom/programs/shell" )
  27.     end,
  28.    
  29.     --[[
  30.    
  31.     EXAMPLE:
  32.    
  33.     function()
  34.         os.run( {}, "/my/secret/stuff/secretApplication" )
  35.     end
  36.     ]]
  37. }
  38.  
  39. local oldState = {}
  40. local msgs = true
  41.  
  42. local oldErr = printError
  43.  
  44. local function inject()
  45.     _G.printError = oldErr
  46.     term.setCursorPos(1,1)
  47.     term.clear()
  48.     _G['rednet'] = nil
  49.     os.loadAPI("/rom/apis/rednet")
  50.     local ok, err = pcall( function()
  51.     parallel.waitForAny(
  52.         unpack(progs)
  53.     )
  54.    
  55.     end )
  56. end
  57.  
  58. _G.printError = inject
  59. os.queueEvent("terminate")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement