Skip to content

Instantly share code, notes, and snippets.

@keharriso
Created November 29, 2016 22:42
Show Gist options
  • Select an option

  • Save keharriso/2611c06249231bf44b60ec3ab237cb92 to your computer and use it in GitHub Desktop.

Select an option

Save keharriso/2611c06249231bf44b60ec3ab237cb92 to your computer and use it in GitHub Desktop.
Package loader for love.filesystem moon scripts.
local moonscript = require "moonscript"
-- Add package loader for love.filesystem moon scripts.
table.insert(package.loaders, 2, function (name)
local name_path = name:gsub("%.", "/")
local file_path, text
for path in love.filesystem.getRequirePath():gsub("%.lua", ".moon"):gmatch("[^;]+") do
file_path = path:gsub("?", name_path)
text = love.filesystem.read(file_path)
if text then
break
end
end
if text then
res, err = moonscript.loadstring(text, "@"..file_path)
if not res then
error(file_path..": "..err)
end
return res
end
return nil, "Could not find moon file"
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment