Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CC Compiler thing
- --The minifier is at https://pastebin.com/dqHRhQi2
- local function expected(argument, got, expected)
- local argument = tostring(argument) or argument
- local text = "Argument #"..argument..", expected " .. expected .. "."
- error(text)
- end
- local function compile(code, bMinify)
- if bMinify then
- os.loadAPI("minify.lua")
- local minify = _G.minify
- _G.minify = nil
- end
- if type(code) ~= "string" then
- expected(1, type(code), "string")
- end
- if minify then
- local code = minify.Rebuild.MinifyFile(code) or code
- end
- return string.dump(load(code))
- end
- local function exportCode(code, bMinify, file)
- if type(code) ~= "string" then
- expected(1, type(code), "string")
- end
- if file ~= nil and type(file) ~= "string" then
- expected(2, type(code), "string")
- end
- if file then
- local handle = fs.open(file, "w")
- handle.write("load("..code..")")
- handle.close()
- end
- return compile(code, bMinify)
- end
- local function loadFile(file)
- local handle = fs.open(file, "r")
- local contents = handle.readAll()
- local handle = nil
- if not load then
- error("loadString is deprecated. (please use Lua >5.1)")
- end
- return load(contents)
- end
- local function loadE(code)
- if not load then
- error("loadString is deprecated. (please use Lua >5.1)")
- end
- return load(code)
- end
- 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