function load(file)
file = fs.open(file, "r")
file2 = file.readAll()
file.close()
return file2
end
function write(file,text)
local code = [[local t = ""
for i = 1, #c do
t = t .. string.char(c[i])
end
local f = assert(loadstring(t, shell.getRunningProgram()))
local env = {shell = shell}
setmetatable(env, {__index = _G})
setfenv(f, env)
f(...)
]]
file = fs.open(file, "w")
file.writeLine("local c = " ..text)
file.writeLine(code)
file.close()
end
local function ser (t)
local text = "{"
for i = 1, #t do
text = text .. t[i] .. ","
end
return text .. "}"
end
function dump(file)
local tab = {}
for i = 1, #file do
table.insert(tab, file:sub(i, i):byte())
end
return ser(tab)
end
function close(fileL, fileW)
fileLoad = load(fileL)
fileDump = dump(fileLoad)
write(fileW, fileDump)
end
local fileLoad, fileWrite = ...
if fileLoad == nil or fileWrite == nil then
print("Usage: " .. shell.getRunningProgram() .. " <sourceFile> <closedSourceFile>")
else
close(fileLoad, fileWrite)
print("Done!")
end