PHP like autoloader idea

Hello everybody! As I am working an a gamemode I wanted to make it dev-friendly, so I thought of making some kind of an autoloader for a library system. As I worked with PHP quite a lot, I made my autoloader as close to the one available in PHP. The current autoloader I did is not finished and I just spent a few hours of the night on it. Take a look at it:


--[[
	Description: This library autoloads all the libraries and LUA files
	in the given folders.
]]--

MYGAMEMODE.autoloader = {};

MYGAMEMODE.autoloader.folders = {};

PREFIX_SERVERSIDE = 'sv';
PREFIX_CLIENTSIDE = 'cl';
PREFIX_SHARED	  = 'sh';


function MYGAMEMODE.autoloader.RegisterFolder(folder)
	if (file.IsDir(folder, 'LUA')) then
		table.insert(MYGAMEMODE.autoloader.folders, folder)
	end
end

--[[
	Description: Loads a library.

	Arguments:	folder	string		Folder containing the library file.
				file	string		The Library file.
]]--
function MYGAMEMODE.autoloader.LoadLib(folder, file)
	local prefix  = string.Explode('_', file)[1];
	local libname = string.Explode('_', file)[2];
	
	local function Include()
		this = {};
		include(folder .. file);
		if (this.short != NULL) then
			KRYSTAL[this.short] = this;
		else
			KRYSTAL[libname] = this;
		end
	end
	
	if (prefix == PREFIX_SERVERSIDE) then
		if (SERVER) then
			Include();
		end
	elseif (prefix == PREFIX_CLIENTSIDE) then
		if (SERVER) then
			AddCSLuaFile(folder .. file);
		else
			Include();
		end
	elseif (prefix == PREFIX_SHARED) then
		if (SERVER) then
			Include();
			AddCSLuaFile(folder .. file);
		else
			Include();
		end
	end
end

--[[
	Description: Loads a folder containing libraries.

	Arguments:	folder	string		Folder containing the libraries.
]]--
function MYGAMEMODE.autoloader.LoadLibs(folder)
	local files = file.Find( folder .. '*.lua', 'LUA');
	
	
	for _, f in pairs(files) do
		MYGAMEMODE.autoloader.LoadLib(folder, f);
	end
end

--[[
	Description: Runs the Autoloader.
]]--
function MYGAMEMODE.autoloader.Run()
	
	for _, folder in pairs(MYGAMEMODE.autoloader.folders) do
		MYGAMEMODE.autoloader.LoadLibs(folder);
	end
end

It would make the libraries look like this:


function this.HelloWorld()
	print('Hello World!');
end

And let’s say this library is a file called ‘sv_helloworld.lua’. This would mean the file would be included only serverside and that you could access the function “HelloWorld” from other files by calling MYGAMEMODE.helloworld.HelloWorld().
For the autoloader to work, you also need to tell him which folders you want it to browse thanks to the RegisterFolder function. When you registered all your folders containing libraries, you just run it with the Run function.

I’d just like to know what you all think of this idea. I feel like it would make making libraries easier, as they all would follow the same standard. So yeah, I am just looking out for opinions and insights about this idea, please. Thank you!

Autoloaders are better than sex. Anything I wrote for garrysmod used them, even tiny addons. Being able to just throw scripts in and forget the junk is great.

Sure, but do you think I should use the “this” to point at the current library (like in PHP) or should I avoid doing it? This makes up for more understandable codes and also makes them quicker to write, but on the other side no other library system uses this, so adapting libraries not originally made for this system might be annoying. I also thought to make a “constructor” function if I keep using “this”, it would be called when the library has been loaded. What do you think of all that? Thanks!

PS: I never should have clicked on foxcock…