KaoSDlanor

Steal toplevel

Jul 24th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[ this is an edit of something that WAS NOT MY IDEA. it's awesome though :) ]]
  2.  
  3. local level,maxlevel=1,0
  4. local resume,pR=coroutine.resume,os.pullEventRaw
  5.  
  6. getUp=function()
  7.     local at,lastFunc,fileName=1
  8.     while true do
  9.         local ok,func=pcall(function() return setfenv(at,getfenv(at)) end)
  10.         local _,err=pcall(error,"err",at)
  11.         if ok then
  12.             lastFunc=func
  13.             fileName=err:match("(.-):")
  14.         else
  15.             return lastFunc,fileName
  16.         end
  17.         at=at+1
  18.     end
  19. end
  20.  
  21. os.pullEventRaw=function(...)
  22.     if level>=maxlevel then
  23.         maxlevel=level
  24.         os.originator={getUp()}
  25.     end
  26.     level=level+1
  27.     return coroutine.yield(...)
  28. end
  29. coroutine.resume=function(...)
  30.     level=level-1
  31.     return resume(...)
  32. end
  33.  
  34. os.queueEvent("ohi")
  35. os.pullEventRaw()
  36.  
  37. coroutine.resume=resume
  38. os.pullEventRaw=pR
Advertisement
Add Comment
Please, Sign In to add comment