mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Let core.get_mod_storage be called multiple times (#12572)
This commit is contained in:
parent
2351c95612
commit
d631f21024
@ -5,6 +5,7 @@ local commonpath = scriptpath.."common"..DIR_DELIM
|
||||
|
||||
dofile(clientpath .. "register.lua")
|
||||
dofile(commonpath .. "after.lua")
|
||||
dofile(commonpath .. "mod_storage.lua")
|
||||
dofile(commonpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "death_formspec.lua")
|
||||
|
19
builtin/common/mod_storage.lua
Normal file
19
builtin/common/mod_storage.lua
Normal 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
|
@ -17,6 +17,7 @@ if core.settings:get_bool("profiler.load") then
|
||||
end
|
||||
|
||||
dofile(commonpath .. "after.lua")
|
||||
dofile(commonpath .. "mod_storage.lua")
|
||||
dofile(gamepath .. "item_entity.lua")
|
||||
dofile(gamepath .. "deprecated.lua")
|
||||
dofile(gamepath .. "misc_s.lua")
|
||||
|
@ -25,12 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
int ModApiStorage::l_get_mod_storage(lua_State *L)
|
||||
{
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
|
||||
if (!lua_isstring(L, -1)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string mod_name = readParam<std::string>(L, -1);
|
||||
// Note that this is wrapped in Lua, see builtin/common/mod_storage.lua
|
||||
std::string mod_name = readParam<std::string>(L, 1);
|
||||
|
||||
ModMetadata *store = nullptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user