aboutsummaryrefslogtreecommitdiff
path: root/builtin/common/mod_storage.lua
blob: 7ccf62900d70449b8a80714553ecba0838c84448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- Modify core.get_mod_storage to return the storage for the current mod.

local get_current_modname = core.get_current_modname

local old_get_mod_storage = core.get_mod_storage

local storages = setmetatable({}, {
	__mode = "v", -- values are weak references (can be garbage-collected)
	__index = function(self, modname)
		local storage = old_get_mod_storage(modname)
		self[modname] = storage
		return storage
	end,
})

function core.get_mod_storage()
	local modname = get_current_modname()
	return modname and storages[modname]
end