fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosAdd a VC clones table.ce74f10

v2.1.1
1.4 KiB52 linesraw
1local loader = {}
2
3local log = require("log")
4
5local notification = require("notification")
6local configdir = love.filesystem.getSaveDirectory()
7
8function loader.loadFile(file, clonesTbl)
9	if file and love.filesystem.getInfo(file, "file") then
10		log.info("[CLONES] Load: %s/%s", configdir, file)
11		
12		local status, chunk = pcall(love.filesystem.load, file)
13
14		if not status then
15			-- Failed loading chunk, chunk is an error string
16			log.error(chunk)
17			notification.error(chunk)
18		elseif chunk then
19			-- Create a sandboxed lua environment
20			local env = {}
21			env._G = env
22
23			-- Set the loaded chunk inside the sandbox
24			setfenv(chunk, env)
25
26			local status, custom_clones = pcall(chunk)
27			if not status then
28				-- Failed calling the chunk, custom_clones is an error string
29				log.error(custom_clones)
30				notification.error(custom_clones)
31			else
32				local num_clones = 0
33				for clone_id, clones in pairs(custom_clones) do
34					if type(clones) == "table" then
35						clonesTbl[clone_id] = {}
36						for version, info in pairs(clones) do
37							if info.id and info.version then
38								num_clones = num_clones + 1
39								log.debug("[CLONES] %s[%d] = %s[%d]", clone_id, version, info.id, info.version)
40								clonesTbl[clone_id][version] = info
41							end
42						end
43					end
44				end
45				log.info("[CLONES] Loaded %d clones from %s", num_clones, file)
46				notification.coloredMessage(("Loaded %d clones from %s"):format(num_clones, file))
47			end
48		end
49	end
50end
51
52return loader