mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
In-game settings menu using separate Lua environment (#15614)
This commit is contained in:
parent
3cb07d5fb6
commit
eeb6cab4c4
48 changed files with 652 additions and 290 deletions
68
src/script/scripting_pause_menu.cpp
Normal file
68
src/script/scripting_pause_menu.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#include "scripting_pause_menu.h"
|
||||
#include "client/client.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "filesys.h"
|
||||
#include "lua_api/l_client_common.h"
|
||||
#include "lua_api/l_menu_common.h"
|
||||
#include "lua_api/l_pause_menu.h"
|
||||
#include "lua_api/l_settings.h"
|
||||
#include "lua_api/l_util.h"
|
||||
#include "porting.h"
|
||||
|
||||
PauseMenuScripting::PauseMenuScripting(Client *client):
|
||||
ScriptApiBase(ScriptingType::PauseMenu)
|
||||
{
|
||||
setGameDef(client);
|
||||
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
initializeSecurity();
|
||||
|
||||
lua_getglobal(L, "core");
|
||||
int top = lua_gettop(L);
|
||||
|
||||
// Initialize our lua_api modules
|
||||
initializeModApi(L, top);
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Push builtin initialization type
|
||||
lua_pushstring(L, "pause_menu");
|
||||
lua_setglobal(L, "INIT");
|
||||
|
||||
infostream << "SCRIPTAPI: Initialized pause menu modules" << std::endl;
|
||||
}
|
||||
|
||||
void PauseMenuScripting::initializeModApi(lua_State *L, int top)
|
||||
{
|
||||
// Register reference classes (userdata)
|
||||
LuaSettings::Register(L);
|
||||
|
||||
// Initialize mod API modules
|
||||
ModApiPauseMenu::Initialize(L, top);
|
||||
ModApiMenuCommon::Initialize(L, top);
|
||||
ModApiClientCommon::Initialize(L, top);
|
||||
ModApiUtil::Initialize(L, top);
|
||||
}
|
||||
|
||||
void PauseMenuScripting::loadBuiltin()
|
||||
{
|
||||
loadScript(porting::path_share + DIR_DELIM "builtin" DIR_DELIM "init.lua");
|
||||
checkSetByBuiltin();
|
||||
}
|
||||
|
||||
bool PauseMenuScripting::checkPathInternal(const std::string &abs_path, bool write_required,
|
||||
bool *write_allowed)
|
||||
{
|
||||
// NOTE: The pause menu env is on the same level of trust as the mainmenu env.
|
||||
// However, since it doesn't need anything else at the moment, there's no
|
||||
// reason to give it access to anything else.
|
||||
|
||||
if (write_required)
|
||||
return false;
|
||||
std::string path_share = fs::AbsolutePath(porting::path_share);
|
||||
return !path_share.empty() && fs::PathStartsWith(abs_path, path_share + DIR_DELIM "builtin");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue