Advertisement
devomaa

Untitled

Jun 29th, 2020
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. --CC Compiler thing
  2. --The minifier is at https://pastebin.com/dqHRhQi2
  3. local function expected(argument, got, expected)
  4. local argument = tostring(argument) or argument
  5. local text = "Argument #"..argument..", expected " .. expected .. "."
  6. error(text)
  7. end
  8. local function compile(code, bMinify)
  9. if bMinify then
  10. os.loadAPI("minify.lua")
  11. local minify = _G.minify
  12. _G.minify = nil
  13. end
  14. if type(code) ~= "string" then
  15. expected(1, type(code), "string")
  16. end
  17. if minify then
  18. local code = minify.Rebuild.MinifyFile(code) or code
  19. end
  20. return string.dump(load(code))
  21. end
  22. local function exportCode(code, bMinify, file)
  23. if type(code) ~= "string" then
  24. expected(1, type(code), "string")
  25. end
  26. if file ~= nil and type(file) ~= "string" then
  27. expected(2, type(code), "string")
  28. end
  29. if file then
  30. local handle = fs.open(file, "w")
  31. handle.write("load("..code..")")
  32. handle.close()
  33. end
  34. return compile(code, bMinify)
  35. end
  36. local function loadFile(file)
  37. local handle = fs.open(file, "r")
  38. local contents = handle.readAll()
  39. local handle = nil
  40. if not load then
  41. error("loadString is deprecated. (please use Lua >5.1)")
  42. end
  43. return load(contents)
  44. end
  45. local function loadE(code)
  46. if not load then
  47. error("loadString is deprecated. (please use Lua >5.1)")
  48. end
  49. return load(code)
  50. end
  51.  
  52. return { ["compile"] = compile, ["loadFile"] = loadFile, ["load"] = loadE, ["exportCode"] = exportCode, ["run"] = loadE, ["loadCode"] = loadE, ["loadCodeFromFile"] = loadFile, ["loadCode"] = loadE }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement