Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Meta/meta.lua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
41 lines (37 sloc)
1.07 KB
This file contains 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 readfile | |
| if love then | |
| readfile = function(name) | |
| if not love.filesystem.exists(name) then return false end | |
| return love.filesystem.read(name) | |
| end | |
| else | |
| readfile = function(name) | |
| local f = io.open(name, "r") | |
| if not f then return false end | |
| local contents = f:read("*a") | |
| f:close() | |
| return contents | |
| end | |
| end | |
| local varname = "([%w%d%.:_%[%]]+)" | |
| local substitionrules = { | |
| [varname .. "%s*%+="] = "%1 = %1 + ", | |
| [varname .. "%s*%-="] = "%1 = %1 - ", | |
| [varname .. "%s*%*="] = "%1 = %1 * ", | |
| [varname .. "%s*/="] = "%1 = %1 / ", | |
| [varname .. "%s*^="] = "%1 = %1 ^ ", | |
| [varname .. "%s*%%="] = "%1 = %1 %% ", | |
| [varname .. "%s*&&="] = "%1 = %1 and ", | |
| [varname .. "%s*||="] = "%1 = %1 or ", | |
| [varname .. "%+%+"] = "%1 = %1 + 1", | |
| [varname .. "%-%-"] = "%1 = %1 - 1" | |
| } | |
| table.insert(package.loaders, function(name) | |
| local tokenized_name = name:gsub("%.", "/") .. ".m.lua" | |
| local contents = readfile(tokenized_name) | |
| if not contents then return nil end | |
| for i, v in pairs(substitionrules) do | |
| contents = contents:gsub(i, v) | |
| end | |
| return assert(loadstring(contents, tokenized_name)) | |
| end) | |