-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeta.lua
41 lines (37 loc) · 1.07 KB
/
meta.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)