1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Move values the mainmenu caches to dedicated files (#14433)

This commit is contained in:
sfan5 2024-03-30 11:06:28 +01:00 committed by GitHub
parent bb6782ca58
commit 6c6e48f006
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 142 additions and 132 deletions

View file

@ -1080,44 +1080,6 @@ int ModApiMainMenu::l_do_async_callback(lua_State *L)
return 1;
}
/******************************************************************************/
// this is intentionally a global and not part of MainMenuScripting or such
namespace {
std::unordered_map<std::string, std::string> once_values;
std::mutex once_mutex;
}
int ModApiMainMenu::l_set_once(lua_State *L)
{
std::string key = readParam<std::string>(L, 1);
if (lua_isnil(L, 2))
return 0;
std::string value = readParam<std::string>(L, 2);
{
MutexAutoLock lock(once_mutex);
once_values[key] = value;
}
return 0;
}
int ModApiMainMenu::l_get_once(lua_State *L)
{
std::string key = readParam<std::string>(L, 1);
{
MutexAutoLock lock(once_mutex);
auto it = once_values.find(key);
if (it == once_values.end())
lua_pushnil(L);
else
lua_pushstring(L, it->second.c_str());
}
return 1;
}
/******************************************************************************/
void ModApiMainMenu::Initialize(lua_State *L, int top)
{
@ -1170,8 +1132,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(open_dir);
API_FCT(share_file);
API_FCT(do_async_callback);
API_FCT(set_once);
API_FCT(get_once);
}
/******************************************************************************/