Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local moonc = "D:\\drive\\bin\\moon\\moonc.exe"
- local function loader(modulename)
- local errmsg = ""
- local config = package.config
- local separator = config:sub(3, 3)
- local placeholder = config:sub(5, 5)
- for path in (package.path .. separator):gmatch("(.-)" .. separator) do
- local path, gsubs = path, 0
- path, gsubs = path:gsub("%" .. placeholder, modulename)
- path, gsubs = path:gsub("%.lua$", ".moon")
- if gsubs > 0 then
- local touchfile, err = io.open(path, "rb")
- if touchfile then
- touchfile:close()
- local compfile, err = io.popen(moonc .. " -p " .. path .. " 2>&1", "rb")
- if not compfile then
- error("Error compiling code from " .. path .. ": " .. tostring(err), 2)
- end
- local code = compfile:read("*all"); compfile:close()
- local finderr = code:find(path .. "\tFailed to parse:", 0, true)
- if finderr == 1 then
- error(tostring(code), 2)
- end
- local func, err = loadstring(code, modulename)
- if not func then
- error("Error loading module from " .. path .. ": " .. tostring(err), 2)
- end
- return func
- else
- errmsg = errmsg .. "\n\tno file '" .. path .. "' (moonloader)"
- end
- end
- end
- return errmsg
- end
- table.insert(package.loaders, 2, loader)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement