File inclusion for lazy people :D

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Julxzs
Prole
Posts: 6
Joined: Wed Jul 02, 2014 9:09 pm
Location: England, UK
Contact:

File inclusion for lazy people :D

Post by Julxzs »

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 :nyu:

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
Sharable github link:
https://gist.github.com/Julzso23/79699044ccf85367710d
User avatar
SouL
Prole
Posts: 14
Joined: Mon Jun 30, 2014 1:33 pm

Re: File inclusion for lazy people :D

Post by SouL »

Well, welcome then and thanks for sharing your efforts :megagrin:
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests