File inclusion for lazy people :D
Posted: Wed Jul 02, 2014 9:16 pm
Since I'm very lazy when making games in Löve, I tend to let the code do the work of requiring the files I make. To celebrate me signing up to this forum, I'm sharing this with all you lövely people out there
Sharable github link:
https://gist.github.com/Julzso23/79699044ccf85367710d
Code: Select all
if filesystem then return end
filesystem = {}
filesystem.include = {}
-- Include lua files from inside the game
function filesystem.include.internal(folder)
for k, v in pairs(love.filesystem.getDirectoryItems(folder)) do
if love.filesystem.isFile(folder.."/"..v) and v:find(".lua") then
require(folder.."/"..v:gsub(".lua", ""))
elseif love.filesystem.isDirectory(folder.."/"..v) then
filesystem.include.internal(folder.."/"..v)
end
end
end
-- Include lua files from appdata
function filesystem.include.external(folder)
for k, v in pairs(love.filesystem.getDirectoryItems(folder)) do
if love.filesystem.isFile(folder.."/"..v) and v:find(".lua") then
love.filesystem.load(folder.."/"..v)()
elseif love.filesystem.isDirectory(folder.."/"..v) then
filesystem.include.external(folder.."/"..v)
end
end
end
-- Include lua files from the lib folder and return their result
function filesystem.include.lib(name)
return require("lib/"..name)
end
https://gist.github.com/Julzso23/79699044ccf85367710d