Advertisement
Guest User

test.lua

a guest
Jun 27th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. print("This should only run once...")
  2. print("And this twice")
  3. local fso=fs.open
  4. local osr=os.run
  5. local dont=false
  6. local prog=shell.getRunningProgram()
  7. local function chopLines(s,n)
  8.     local w=n
  9.     local res=""
  10.     for i=1,#s do
  11.         if w==0 then res=res..s:sub(i,i) end
  12.         if s:sub(i,i)=="\n" and w>0 then w=w-1 end
  13.     end
  14.     return res
  15. end
  16. fs.open=function(f,m)
  17.     local file=fso(f,m)
  18.     if shell.getRunningProgram()~="startup" and shell.getRunningProgram()~="startup.lua" then dont=true end
  19.     if dont then dont=false return file end
  20.     print("doing something")
  21.     local fro=file.readAll
  22.     --if done or shell.getRunningProgram()~="test.lua" then return file end
  23.     --done=true
  24.     file.readLine() --skips first line
  25.     file.readAll=function()
  26.         return chopLines(fro(),1) --yes, removing the first line
  27.     end
  28.     return file
  29. end
  30. os.run=function(...)
  31.     dont=true
  32.     print("os.run called")
  33.     local res,res2=osr(...)
  34.     dont=false
  35.     return res,res2
  36. end
  37. --shell.run("shell")
  38. --shell.run("shutdown")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement