Advertisement
ecco7777

CC commentToFile function

Jun 12th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. function stringDel(source,delString)
  2. local stringPos={string.find(source,delString)}
  3. source=string.sub(source,1,stringPos[1]-1)..string.sub(source,stringPos[2]+1)
  4. return(source)
  5. end
  6.  
  7. function commentToFile(fileName)
  8. txt=fs.open(fileName,'r').readAll()
  9. while string.find(txt,'--[$') do
  10. str1={string.find(txt,'--[$')}
  11. txt=stringDel(txt,'--[$')
  12. str2={string.find(txt,'$')}
  13. newFile=string.sub(txt,str1[1],str2[1]-1)
  14. stringDel(txt,newFile..'$')
  15. str3={string.find(txt,'$'..newFile..'$')}
  16. result=string.sub(txt,str1[1],str3[1]-1)
  17. fp=fs.open(fileName,'w')
  18. fp.write(result)
  19. fp.close()
  20. end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement