Skip to content

Commit

Permalink
DRY-ify fennel loader
Browse files Browse the repository at this point in the history
  • Loading branch information
44100hertz committed Sep 19, 2024
1 parent 188f14a commit ab31f16
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
local fennel = require("lib.fennel")
local make_love_searcher = function(env)
return function(module_name)
local path = module_name:gsub("%.", "/") .. ".fnl"
if love.filesystem.getInfo(path) then
return function(...)
local code = love.filesystem.read(path)
return fennel.eval(code, {env=env, filename=path}, ...)
end, path
end
path = module_name:gsub("%.", "/") .. "/init.fnl"
if love.filesystem.getInfo(path) then
return function(...)
local code = love.filesystem.read(path)
return fennel.eval(code, {env=env, filename=path}, ...)
end, path
for _, filename in ipairs({".fnl", "/init.fnl"}) do
local path = module_name:gsub("%.", "/") .. filename
if love.filesystem.getInfo(path) then
return function(...)
local code = love.filesystem.read(path)
return fennel.eval(code, {env=env, filename=path}, ...)
end
end
end
end
end
Expand Down

0 comments on commit ab31f16

Please sign in to comment.