no idea why it dont do anything
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Why code dont work
Started by FuuuAInfiniteLoop(F.A.I.L), 09 February 2013 - 04:30 PMPosted 09 February 2013 - 05:30 PM
pastebin get DBPST1kP compressor
no idea why it dont do anything
no idea why it dont do anything
Posted 09 February 2013 - 05:40 PM
I dont exactly know if this is your only problem but on line 48 you have 2 unexpected symbols change the line to file.write(textutils.serialize(B))
Posted 09 February 2013 - 05:56 PM
corrected code but still not working
args = {...}
function replace(s)
string.gsub(s, "function", "@f")
string.gsub(s, "redstone", "@r")
string.gsub(s, "printError", "@e")
string.gsub(s, "peripheral", "@p")
string.gsub(s, "tonumber", "@tn")
string.gsub(s, "tostring", "@ts")
string.gsub(s, "colors", "@c")
string.gsub(s, "colours", "@c")
string.gsub(s, "setmetatable", "@sm")
string.gsub(s, "getmetatable", "@gm")
string.gsub(s, "textutils", "@tu")
string.gsub(s, "paintutils", "@pu")
string.gsub(s, "then", "@t")
string.gsub(s, "os.pullEvent", "@pe")
string.gsub(s, "--", "@")
return s
end
function replace2(s)
string.gsub(s, "@f", "function")
string.gsub(s, "@r", "redstone")
string.gsub(s, "@e", "printError")
string.gsub(s, "@p", "peripheral")
string.gsub(s, "@tn", "tonumber")
string.gsub(s, "@ts", "tostring")
string.gsub(s, "c", "colors")
string.gsub(s, "@c", "colours")
string.gsub(s, "@sm", "setmetatable")
string.gsub(s, "@gm", "getmetatables")
string.gsub(s, "@tu", "textutils")
string.gsub(s, "@pu", "paintutils")
string.gsub(s, "@t", "then")
string.gsub(s, "@pe", "os.pullEvent")
string.gsub(s, "@", "--")
return s
end
if args[1]=="-create" then
file = fs.open(args[2], "r")
b = {}
while true do
d = file.readLine()
c = fs.open(d, "r")
if not d then break end
a = c.readAll()
b[replace(d)] = a
end
file.close()
file = fs.open("output", "w")
file.write(textutils.serialize(B)/>)
file.close()
elseif args[1]=="-unpack" then
file = fs.open(args[2], "r")
a = textutils.unserialize(file.readLine())
file.close()
for k, v in pairs(a) do
b = fs.open(k, "w")
c = replace2(v)
b.write(c)
b.close()
end
end
Posted 09 February 2013 - 05:57 PM
well no u didnt correct what i told you i can see that it is still there remove the /> from line 48…
Posted 09 February 2013 - 06:01 PM
the pastebin is good but in the forums, when i correct it it appears exactly the same, the pastebin and the code are the same copy but the pasted here dont work(pastebin also dont work but is corrected)
Posted 09 February 2013 - 07:10 PM
What in the heck are you even trying to do? I'm not sure you understand how compression works, or even how you think this should even be doing anything useful. Give us more information.
Posted 09 February 2013 - 09:06 PM
From what i can see with his compression he is trying to lower the amount of bytes by removing words and replacing them with a 2 letter word so function becomes @f or what ever shorting the amount of letters, decreasing the file size, not a very efficient way but might work…
Posted 10 February 2013 - 05:37 AM
First i make a table with the contents and the name of every file and then i replce long luacomands with 2-3 letters words so it will reduce the size of a file a little bitWhat in the heck are you even trying to do? I'm not sure you understand how compression works, or even how you think this should even be doing anything useful. Give us more information.
Posted 11 February 2013 - 12:56 AM
Let's examine a piece of the code, shall we?
So, if the first argument is -create, we perform a few actions. First, we open up a file specified in the next argument. I assume this is a list of filenames that we are supposed to be compressing. Next, we create a table. Then we enter a loop. We read a line of the list of filenames. We attempt to open the filename specified. Then, after already attempting to open it, we check if it was a valid line. If not, we jump out of the loop. Otherwise, we read all of the file. Then we execute the code replacement function on the filename and use it as the index to store the entire unmodified contents of the file. We don't bother closing the file handle for our target file, and just restart the loop. After we finally exit the loop, we close our file list handle.
But wait, it gets even better:
After we do all that, we take our table (which, remember, contains the name and unmodified contents of each file) and write that out to another file. Some compression scheme, huh?
if args[1]=="-create" then
file = fs.open(args[2], "r")
b = {}
while true do
d = file.readLine()
c = fs.open(d, "r")
if not d then break end
a = c.readAll()
b[replace(d)] = a
end
file.close()
So, if the first argument is -create, we perform a few actions. First, we open up a file specified in the next argument. I assume this is a list of filenames that we are supposed to be compressing. Next, we create a table. Then we enter a loop. We read a line of the list of filenames. We attempt to open the filename specified. Then, after already attempting to open it, we check if it was a valid line. If not, we jump out of the loop. Otherwise, we read all of the file. Then we execute the code replacement function on the filename and use it as the index to store the entire unmodified contents of the file. We don't bother closing the file handle for our target file, and just restart the loop. After we finally exit the loop, we close our file list handle.
But wait, it gets even better:
file = fs.open("output", "w")
file.write(textutils.serialize(b))
file.close()
After we do all that, we take our table (which, remember, contains the name and unmodified contents of each file) and write that out to another file. Some compression scheme, huh?
Posted 11 February 2013 - 04:34 AM
the file is commented in pastebin.
compression:
-repalce function like "function" to shorter ones like "@f"
decompression:
-replace the shorter version to her values
compression:
-repalce function like "function" to shorter ones like "@f"
decompression:
-replace the shorter version to her values
Posted 11 February 2013 - 06:59 AM
Your code does not do what you think it does.
Posted 11 February 2013 - 08:10 AM
I have remade it but still getting errors
Posted 11 February 2013 - 02:22 PM
Locked upon request.