Guest User

snippet

a guest
Feb 13th, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. function encode(tText,tForeground,tBackground,sFile)
  2.     if type(tText)=="string" then
  3.         local tTemp = {}
  4.         for word in tText:gmatch("[^\n]+") do
  5.             table.insert(tTemp,{})
  6.             for char in word:gmatch(".") do
  7.                 table.insert(tTemp[#tTemp],char)
  8.             end
  9.         end
  10.         tText = tTemp
  11.     end
  12.     local continue = 0
  13.     local tFile = fs.open(sFile,"wb")
  14.     if #tBackground~=#tForeground or (tText and #tBackground~=#tText) then
  15.         error("size of tables must match. \n#("..tostring(#tForeground)..","..tostring(#tBackground)..","..tostring(tText and #tText or nil)..")")
  16.     end
  17.     for i=1,#tForeground do
  18.         if #tBackground[i]~=#tForeground[i] or (tText and #tBackground[i]~=#tText[i])  then
  19.             error("size of tables must match. \n#"..tostring(i).."#("..tostring(#tForeground[i])..","..tostring(#tBackground[i])..","..tostring(tText and #tText[i] or nil)..")")
  20.         end
  21.         for t=1,#tForeground[i] do
  22.             if continue > 0 then
  23.                 continue = continue - 1
  24.             else
  25.                 if fRepeats(tForeground,tBackground,i,t) > 1 then
  26.                     continue = fRepeats(tForeground,tBackground,i,t)-1
  27.                     tFile.write(1)
  28.                     tFile.write(1)
  29.                     tFile.write(continue+1)
  30.                 end
  31.                 local sBin = tColToBin[tBackground[i][t]][tForeground[i][t]]
  32.                 tFile.write( tBinToDec[tonumber(sBin)] )
  33.             end
  34.         end
  35.         if i~=#tForeground then
  36.             tFile.write(10)
  37.             tFile.write(10)
  38.         end
  39.     end
  40.     if #tText > 0 then
  41.         tFile.write(255)
  42.         tFile.write(255)
  43.         for i=1,#tText do
  44.             for t=1,#tText[i] do
  45.                 if continue > 0 then
  46.                     continue = continue - 1
  47.                 else
  48.                     if fTextReps(tText,i,t) > 1 then
  49.                         continue = fTextReps(tText,i,t) - 1
  50.                         tFile.write(1)
  51.                         tFile.write(continue+1)
  52.                     end
  53.                     tFile.write(string.byte(tText[i][t]))
  54.                 end
  55.             end
  56.             tFile.write(10)
  57.         end
  58.     end
  59.     tFile.close()
  60. end
Advertisement
Add Comment
Please, Sign In to add comment