Splitting plugin in files
#9
It' also possible to use dofile to load a lua file. I have this code, that loads all lua files in the folder from the array folders. This also allows you to structure your files. The code has to be placed outside of a function, in a lua file in your main plugin folder.

function LoadLuaFiles()
	local folders =  { "/code", "/code/classes", "/code/commands" }
	local localFolder = cPluginManager:GetCurrentPlugin():GetLocalFolder()

	for _, folder in pairs(folders) do
		local files = cFile:GetFolderContents(localFolder .. "/" .. folder)
		for _, file in pairs(files) do
			if (string.sub(file, #file -3, #file) == ".lua") then
				dofile(localFolder .. folder .. "/" .. file)
			end
		end
	end
end
LoadLuaFiles()
Reply
Thanks given by:


Messages In This Thread
Splitting plugin in files - by chrobione - 12-18-2015, 10:35 AM
RE: noob Question - by Zee1234 - 12-18-2015, 04:17 PM
RE: noob Question - by chrobione - 12-18-2015, 05:16 PM
RE: Splitting plugin in files - by xoft - 12-18-2015, 05:01 PM
RE: Splitting plugin in files - by chrobione - 12-18-2015, 05:32 PM
RE: Splitting plugin in files - by xoft - 12-18-2015, 05:01 PM
RE: Splitting plugin in files - by Zee1234 - 12-18-2015, 06:00 PM
RE: Splitting plugin in files - by sphinxc0re - 12-18-2015, 06:12 PM
RE: Splitting plugin in files - by Seadragon91 - 12-18-2015, 06:24 PM
RE: Splitting plugin in files - by NiLSPACE - 12-18-2015, 06:31 PM
RE: Splitting plugin in files - by Seadragon91 - 12-18-2015, 06:33 PM
RE: Splitting plugin in files - by chrobione - 12-19-2015, 08:05 AM
RE: Splitting plugin in files - by xoft - 12-18-2015, 06:55 PM
RE: Splitting plugin in files - by worktycho - 12-18-2015, 11:59 PM
RE: Splitting plugin in files - by NiLSPACE - 12-19-2015, 08:11 AM
RE: Splitting plugin in files - by chrobione - 12-19-2015, 08:26 AM



Users browsing this thread: 11 Guest(s)