mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
Refactor how script api reads current mod name
This is to prevent future mistakes and make it clearer whether the mod name can be trusted depending on how it is retrieved.
This commit is contained in:
parent
cb5fa56e17
commit
ce97210eb1
8 changed files with 88 additions and 78 deletions
|
@ -632,12 +632,10 @@ int ModApiUtil::l_get_last_run_mod(lua_State *L)
|
|||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
|
||||
std::string current_mod = readParam<std::string>(L, -1, "");
|
||||
if (current_mod.empty()) {
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
|
||||
}
|
||||
std::string current_mod = ScriptApiBase::getCurrentModNameInsecure(L);
|
||||
if (current_mod.empty())
|
||||
current_mod = getScriptApiBase(L)->getOrigin();
|
||||
lua_pushstring(L, current_mod.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -735,6 +733,9 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
|
|||
API_FCT(colorspec_to_colorstring);
|
||||
API_FCT(colorspec_to_bytes);
|
||||
|
||||
API_FCT(get_last_run_mod);
|
||||
API_FCT(set_last_run_mod);
|
||||
|
||||
API_FCT(urlencode);
|
||||
|
||||
LuaSettings::create(L, g_settings, g_settings_path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue