forked from minetest/minetest
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let core.get_mod_storage be called multiple times (minetest#12572)
- Loading branch information
1 parent
2351c95
commit d631f21
Showing
4 changed files
with
23 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters