Advertisement
Guest User

test.lua

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