Created
November 29, 2016 22:42
-
-
Save keharriso/2611c06249231bf44b60ec3ab237cb92 to your computer and use it in GitHub Desktop.
Package loader for love.filesystem moon scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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