1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Let core.get_mod_storage be called multiple times (#12572)

This commit is contained in:
Jude Melton-Houghton 2022-07-23 16:27:07 -04:00 committed by GitHub
parent 2351c95612
commit d631f21024
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 6 deletions

View file

@ -0,0 +1,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