• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[TFS (any)] Lib folder loader (libs like 0.4)

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
3,323
Solutions
26
Reaction score
2,694
Location
Poland
warning: if your libs contain syntax errors, it won't load global.lua
potential fixes are welcome

with this configuration, it will load all files from data/lib/files folder

add to global.lua:
Code:
dofile('data/lib/loader.lua')

create file loader.lua in data/lib folder:
Code:
------------------------------
-- Loader config
------------------------------
local modDir = "data/lib"
local modOutput = true
local folders = {'files'} -- folders to include
------------------------------
-- Loader
------------------------------
local dirCommand = {'find ', ' -maxdepth 1 -type f'}

-- Windows compability
local platform_windows = false
if io.popen("ver"):read("*all"):find("Windows") then
	dirCommand = {'dir "', '" /b /aa'}
	platform_windows = true
end

-- lua files loader
local filesCount = 0
for i = 1, #folders do
	if modOutput then
		io.write('>> Loading ' .. folders[i] .. '... ')
	end

	for dir in io.popen(dirCommand[1] .. modDir .. folders[i] .. '/' .. dirCommand[2]):lines() do
		filesCount = filesCount + 1
		local dirstr = (platform_windows and modDir .. folders[i] .. '/' .. dir or dir)
		dofile(dirstr)
	end

	if modOutput then
		print(filesCount .. ' file(s) loaded')
	end
	
	filesCount = 0
end
 
Back
Top