Alyssa

Source close

Aug 17th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. -- Not mine, just borrowed so I can use in CC
  2. function load(file)
  3.   file = fs.open(file, "r")
  4.   file2 = file.readAll()
  5.   file.close()
  6.   return file2
  7. end
  8.  
  9. function write(file,text)
  10. local code = [[local t = ""
  11. for i = 1, #c do
  12.   t = t .. string.char(c[i])
  13. end
  14. local f = assert(loadstring(t, shell.getRunningProgram()))
  15. local env = {shell = shell}
  16. setmetatable(env, {__index = _G})
  17. setfenv(f, env)
  18. f(...)
  19. ]]
  20.  
  21.   file = fs.open(file, "w")
  22.   file.writeLine("local c = " ..text)
  23.   file.writeLine(code)
  24.   file.close()
  25. end
  26.  
  27. local function ser (t)
  28.   local text = "{"
  29.  
  30.   for i = 1, #t do
  31.         text = text .. t[i] .. ","
  32.   end
  33.  
  34.   return text .. "}"
  35. end
  36.  
  37. function dump(file)
  38.   local tab = {}
  39.  
  40.   for i = 1, #file do
  41.         table.insert(tab, file:sub(i, i):byte())
  42.   end
  43.  
  44.   return ser(tab)
  45. end
  46.  
  47. function close(fileL, fileW)
  48.   fileLoad = load(fileL)
  49.   fileDump = dump(fileLoad)
  50.   write(fileW, fileDump)
  51. end
  52.  
  53. local fileLoad, fileWrite = ...
  54.  
  55. if fileLoad == nil or fileWrite == nil then
  56.   print("Usage: " .. shell.getRunningProgram() .. " <sourceFile> <closedSourceFile>")
  57. else
  58.   close(fileLoad, fileWrite)
  59.   print("Done!")
  60. end
Advertisement
Add Comment
Please, Sign In to add comment