Advertisement
ecco7777

CC write in file

Aug 22nd, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. -- Open file
  2.     local sDir = string.sub(sPath, 1, #sPath - #fs.getName(sPath))
  3.     if not fs.exists(sDir) then
  4.         fs.makeDir(sDir)
  5.     end
  6.  
  7.     local file = fs.open( path, "w" )
  8.     if not file then
  9.         return false
  10.     end
  11.  
  12.     -- Encode (and trim)
  13.     local tLines = {}
  14.     local nLastLine = 0
  15.     for y=1,h-1 do
  16.         local sLine = ""
  17.         local nLastChar = 0
  18.         for x=1,w-2 do
  19.             local c = getCharOf( getCanvasPixel( x, y ) )
  20.             sLine = sLine .. c
  21.             if c ~= " " then
  22.                 nLastChar = x
  23.             end
  24.         end
  25.         sLine = string.sub( sLine, 1, nLastChar )
  26.         tLines[y] = sLine
  27.         if string.len( sLine ) > 0 then
  28.             nLastLine = y
  29.         end
  30.     end
  31.  
  32.     -- Save out
  33.     for n=1,nLastLine do
  34.         file.writeLine( tLines[ n ] )
  35.     end
  36.     file.close()
  37.     return true
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement