Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function encode(tText,tForeground,tBackground,sFile)
- if type(tText)=="string" then
- local tTemp = {}
- for word in tText:gmatch("[^\n]+") do
- table.insert(tTemp,{})
- for char in word:gmatch(".") do
- table.insert(tTemp[#tTemp],char)
- end
- end
- tText = tTemp
- end
- local continue = 0
- local tFile = fs.open(sFile,"wb")
- if #tBackground~=#tForeground or (tText and #tBackground~=#tText) then
- error("size of tables must match. \n#("..tostring(#tForeground)..","..tostring(#tBackground)..","..tostring(tText and #tText or nil)..")")
- end
- for i=1,#tForeground do
- if #tBackground[i]~=#tForeground[i] or (tText and #tBackground[i]~=#tText[i]) then
- error("size of tables must match. \n#"..tostring(i).."#("..tostring(#tForeground[i])..","..tostring(#tBackground[i])..","..tostring(tText and #tText[i] or nil)..")")
- end
- for t=1,#tForeground[i] do
- if continue > 0 then
- continue = continue - 1
- else
- if fRepeats(tForeground,tBackground,i,t) > 1 then
- continue = fRepeats(tForeground,tBackground,i,t)-1
- tFile.write(1)
- tFile.write(1)
- tFile.write(continue+1)
- end
- local sBin = tColToBin[tBackground[i][t]][tForeground[i][t]]
- tFile.write( tBinToDec[tonumber(sBin)] )
- end
- end
- if i~=#tForeground then
- tFile.write(10)
- tFile.write(10)
- end
- end
- if #tText > 0 then
- tFile.write(255)
- tFile.write(255)
- for i=1,#tText do
- for t=1,#tText[i] do
- if continue > 0 then
- continue = continue - 1
- else
- if fTextReps(tText,i,t) > 1 then
- continue = fTextReps(tText,i,t) - 1
- tFile.write(1)
- tFile.write(continue+1)
- end
- tFile.write(string.byte(tText[i][t]))
- end
- end
- tFile.write(10)
- end
- end
- tFile.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment