A new Lua environment is born
TODO: fix copyright headers
This commit is contained in:
parent
0a67e6180d
commit
f8cf405ec9
@ -78,6 +78,8 @@ elseif INIT == "client" then
|
||||
dofile(scriptdir .. "client" .. DIR_DELIM .. "init.lua")
|
||||
elseif INIT == "emerge" then
|
||||
dofile(scriptdir .. "emerge" .. DIR_DELIM .. "init.lua")
|
||||
elseif INIT == "pause_menu" then
|
||||
print("WOW WOW WOW HELLO FROM PAUSE MENU ENV")
|
||||
else
|
||||
error(("Unrecognized builtin initialization type %s!"):format(tostring(INIT)))
|
||||
end
|
||||
|
@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "irr_v3d.h"
|
||||
#include "scripting_pause_menu.h"
|
||||
|
||||
class Client;
|
||||
class RenderingEngine;
|
||||
@ -27,6 +29,8 @@ struct GameFormSpec
|
||||
m_client = client;
|
||||
m_rendering_engine = rendering_engine;
|
||||
m_input = input;
|
||||
m_pause_script = std::make_unique<PauseMenuScripting>(client);
|
||||
m_pause_script->loadBuiltin();
|
||||
}
|
||||
|
||||
~GameFormSpec();
|
||||
@ -52,6 +56,7 @@ private:
|
||||
Client *m_client;
|
||||
RenderingEngine *m_rendering_engine;
|
||||
InputHandler *m_input;
|
||||
std::unique_ptr<PauseMenuScripting> m_pause_script;
|
||||
|
||||
// Default: "". If other than "": Empty show_formspec packets will only
|
||||
// close the formspec when the formname matches
|
||||
|
@ -15,6 +15,7 @@ set(common_SCRIPT_SRCS
|
||||
set(client_SCRIPT_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/scripting_mainmenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/scripting_client.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/scripting_pause_menu.cpp
|
||||
${client_SCRIPT_COMMON_SRCS}
|
||||
${client_SCRIPT_CPP_API_SRCS}
|
||||
${client_SCRIPT_LUA_API_SRCS}
|
||||
|
@ -16,6 +16,8 @@ set(common_SCRIPT_CPP_API_SRCS
|
||||
|
||||
set(client_SCRIPT_CPP_API_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_client.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_client_common.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_mainmenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/s_pause_menu.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
|
@ -203,7 +203,7 @@ void ScriptApiBase::checkSetByBuiltin()
|
||||
{
|
||||
lua_State *L = getStack();
|
||||
|
||||
if (m_gamedef) {
|
||||
if (m_gamedef && getType() != ScriptingType::PauseMenu) {
|
||||
CHECK(CUSTOM_RIDX_READ_VECTOR, "read_vector");
|
||||
CHECK(CUSTOM_RIDX_PUSH_VECTOR, "push_vector");
|
||||
CHECK(CUSTOM_RIDX_READ_NODE, "read_node");
|
||||
|
@ -47,7 +47,8 @@ enum class ScriptingType: u8 {
|
||||
Client,
|
||||
MainMenu,
|
||||
Server,
|
||||
Emerge
|
||||
Emerge,
|
||||
PauseMenu,
|
||||
};
|
||||
|
||||
class Server;
|
||||
|
@ -126,34 +126,6 @@ void ScriptApiClient::environment_step(float dtime)
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiClient::on_formspec_input(const std::string &formname,
|
||||
const StringMap &fields)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_chat_messages
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_formspec_input");
|
||||
// Call callbacks
|
||||
// param 1
|
||||
lua_pushstring(L, formname.c_str());
|
||||
// param 2
|
||||
lua_newtable(L);
|
||||
StringMap::const_iterator it;
|
||||
for (it = fields.begin(); it != fields.end(); ++it) {
|
||||
const std::string &name = it->first;
|
||||
const std::string &value = it->second;
|
||||
lua_pushstring(L, name.c_str());
|
||||
lua_pushlstring(L, value.c_str(), value.size());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
@ -35,7 +35,6 @@ public:
|
||||
void on_damage_taken(int32_t damage_amount);
|
||||
void on_hp_modification(int32_t newhp);
|
||||
void environment_step(float dtime);
|
||||
void on_formspec_input(const std::string &formname, const StringMap &fields);
|
||||
|
||||
bool on_dignode(v3s16 p, MapNode node);
|
||||
bool on_punchnode(v3s16 p, MapNode node);
|
||||
|
37
src/script/cpp_api/s_client_common.cpp
Normal file
37
src/script/cpp_api/s_client_common.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#include "s_client_common.h"
|
||||
#include "s_internal.h"
|
||||
#include "client/client.h"
|
||||
|
||||
bool ScriptApiClientCommon::on_formspec_input(const std::string &formname,
|
||||
const StringMap &fields)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
// Get core.registered_on_formspec_inputs
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "registered_on_formspec_input");
|
||||
// Call callbacks
|
||||
// param 1
|
||||
lua_pushstring(L, formname.c_str());
|
||||
// param 2
|
||||
lua_newtable(L);
|
||||
StringMap::const_iterator it;
|
||||
for (it = fields.begin(); it != fields.end(); ++it) {
|
||||
const std::string &name = it->first;
|
||||
const std::string &value = it->second;
|
||||
lua_pushstring(L, name.c_str());
|
||||
lua_pushlstring(L, value.c_str(), value.size());
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
|
||||
} catch (LuaError &e) {
|
||||
getClient()->setFatalError(e);
|
||||
return true;
|
||||
}
|
||||
return readParam<bool>(L, -1);
|
||||
}
|
14
src/script/cpp_api/s_client_common.h
Normal file
14
src/script/cpp_api/s_client_common.h
Normal file
@ -0,0 +1,14 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "util/string.h"
|
||||
|
||||
class ScriptApiClientCommon : virtual public ScriptApiBase
|
||||
{
|
||||
public:
|
||||
bool on_formspec_input(const std::string &formname, const StringMap &fields);
|
||||
};
|
27
src/script/cpp_api/s_pause_menu.cpp
Normal file
27
src/script/cpp_api/s_pause_menu.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#include "s_pause_menu.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
|
||||
void ScriptApiPauseMenu::open_settings()
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||
|
||||
// Get handler function
|
||||
lua_getglobal(L, "core");
|
||||
lua_getfield(L, -1, "open_settings");
|
||||
lua_remove(L, -2); // Remove core
|
||||
if (lua_isnil(L, -1)) {
|
||||
lua_pop(L, 1); // Pop open_settings
|
||||
return;
|
||||
}
|
||||
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||
|
||||
// Call it
|
||||
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
|
||||
lua_pop(L, 1); // Pop error handler
|
||||
}
|
13
src/script/cpp_api/s_pause_menu.h
Normal file
13
src/script/cpp_api/s_pause_menu.h
Normal file
@ -0,0 +1,13 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
|
||||
class ScriptApiPauseMenu : virtual public ScriptApiBase
|
||||
{
|
||||
public:
|
||||
void open_settings();
|
||||
};
|
@ -29,10 +29,12 @@ set(common_SCRIPT_LUA_API_SRCS
|
||||
set(client_SCRIPT_LUA_API_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_camera.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_client.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_client_common.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_client_sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_localplayer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_mainmenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_mainmenu_sound.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_menu_common.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_minimap.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_particles_local.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_storage.cpp
|
||||
|
@ -127,21 +127,6 @@ int ModApiClient::l_get_player_names(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// show_formspec(formspec)
|
||||
int ModApiClient::l_show_formspec(lua_State *L)
|
||||
{
|
||||
if (!lua_isstring(L, 1) || !lua_isstring(L, 2))
|
||||
return 0;
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SHOW_LOCAL_FORMSPEC;
|
||||
event->show_formspec.formname = new std::string(luaL_checkstring(L, 1));
|
||||
event->show_formspec.formspec = new std::string(luaL_checkstring(L, 2));
|
||||
getClient(L)->pushToEventQueue(event);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// disconnect()
|
||||
int ModApiClient::l_disconnect(lua_State *L)
|
||||
{
|
||||
@ -325,7 +310,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
|
||||
API_FCT(send_chat_message);
|
||||
API_FCT(clear_out_chat_queue);
|
||||
API_FCT(get_player_names);
|
||||
API_FCT(show_formspec);
|
||||
API_FCT(gettext);
|
||||
API_FCT(get_node_or_nil);
|
||||
API_FCT(disconnect);
|
||||
|
@ -33,9 +33,6 @@ private:
|
||||
// get_player_names()
|
||||
static int l_get_player_names(lua_State *L);
|
||||
|
||||
// show_formspec(name, formspec)
|
||||
static int l_show_formspec(lua_State *L);
|
||||
|
||||
// disconnect()
|
||||
static int l_disconnect(lua_State *L);
|
||||
|
||||
|
29
src/script/lua_api/l_client_common.cpp
Normal file
29
src/script/lua_api/l_client_common.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#include "l_client_common.h"
|
||||
|
||||
#include "client/client.h"
|
||||
#include "client/clientevent.h"
|
||||
#include "lua_api/l_internal.h"
|
||||
|
||||
// show_formspec(formspec)
|
||||
int ModApiClientCommon::l_show_formspec(lua_State *L)
|
||||
{
|
||||
if (!lua_isstring(L, 1) || !lua_isstring(L, 2))
|
||||
return 0;
|
||||
|
||||
ClientEvent *event = new ClientEvent();
|
||||
event->type = CE_SHOW_LOCAL_FORMSPEC;
|
||||
event->show_formspec.formname = new std::string(luaL_checkstring(L, 1));
|
||||
event->show_formspec.formspec = new std::string(luaL_checkstring(L, 2));
|
||||
getClient(L)->pushToEventQueue(event);
|
||||
lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ModApiClientCommon::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(show_formspec);
|
||||
}
|
17
src/script/lua_api/l_client_common.h
Normal file
17
src/script/lua_api/l_client_common.h
Normal file
@ -0,0 +1,17 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lua_api/l_base.h"
|
||||
|
||||
class ModApiClientCommon : public ModApiBase
|
||||
{
|
||||
private:
|
||||
// show_formspec(name, formspec)
|
||||
static int l_show_formspec(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
};
|
@ -907,16 +907,6 @@ int ModApiMainMenu::l_get_language(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_gettext(lua_State *L)
|
||||
{
|
||||
const char *srctext = luaL_checkstring(L, 1);
|
||||
const char *text = *srctext ? gettext(srctext) : "";
|
||||
lua_pushstring(L, text);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_window_info(lua_State *L)
|
||||
{
|
||||
@ -949,14 +939,6 @@ int ModApiMainMenu::l_get_window_info(lua_State *L)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_active_driver(lua_State *L)
|
||||
{
|
||||
auto drivertype = RenderingEngine::get_video_driver()->getDriverType();
|
||||
lua_pushstring(L, RenderingEngine::getVideoDriverInfo(drivertype).name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int ModApiMainMenu::l_get_active_renderer(lua_State *L)
|
||||
{
|
||||
lua_pushstring(L, RenderingEngine::get_video_driver()->getName());
|
||||
@ -980,14 +962,6 @@ int ModApiMainMenu::l_get_active_irrlicht_device(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_irrlicht_device_supports_touch(lua_State *L)
|
||||
{
|
||||
lua_pushboolean(L, RenderingEngine::get_raw_device()->supportsTouchEvents());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
|
||||
{
|
||||
@ -1122,13 +1096,10 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
||||
API_FCT(show_path_select_dialog);
|
||||
API_FCT(download_file);
|
||||
API_FCT(get_language);
|
||||
API_FCT(gettext);
|
||||
API_FCT(get_video_drivers);
|
||||
API_FCT(get_window_info);
|
||||
API_FCT(get_active_driver);
|
||||
API_FCT(get_active_renderer);
|
||||
API_FCT(get_active_irrlicht_device);
|
||||
API_FCT(irrlicht_device_supports_touch);
|
||||
API_FCT(get_min_supp_proto);
|
||||
API_FCT(get_max_supp_proto);
|
||||
API_FCT(get_formspec_version);
|
||||
@ -1165,5 +1136,4 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
|
||||
API_FCT(get_max_supp_proto);
|
||||
API_FCT(get_formspec_version);
|
||||
API_FCT(get_language);
|
||||
API_FCT(gettext);
|
||||
}
|
||||
|
@ -53,8 +53,6 @@ private:
|
||||
|
||||
static int l_get_language(lua_State *L);
|
||||
|
||||
static int l_gettext(lua_State *L);
|
||||
|
||||
//packages
|
||||
|
||||
static int l_get_games(lua_State *L);
|
||||
@ -89,14 +87,10 @@ private:
|
||||
|
||||
static int l_get_window_info(lua_State *L);
|
||||
|
||||
static int l_get_active_driver(lua_State *L);
|
||||
|
||||
static int l_get_active_renderer(lua_State *L);
|
||||
|
||||
static int l_get_active_irrlicht_device(lua_State *L);
|
||||
|
||||
static int l_irrlicht_device_supports_touch(lua_State *L);
|
||||
|
||||
//filesystem
|
||||
|
||||
static int l_get_mainmenu_path(lua_State *L);
|
||||
|
48
src/script/lua_api/l_menu_common.cpp
Normal file
48
src/script/lua_api/l_menu_common.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#include "l_menu_common.h"
|
||||
|
||||
#include "client/renderingengine.h"
|
||||
#include "gettext.h"
|
||||
#include "lua_api/l_internal.h"
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMenuCommon::l_gettext(lua_State *L)
|
||||
{
|
||||
const char *srctext = luaL_checkstring(L, 1);
|
||||
const char *text = *srctext ? gettext(srctext) : "";
|
||||
lua_pushstring(L, text);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMenuCommon::l_get_active_driver(lua_State *L)
|
||||
{
|
||||
auto drivertype = RenderingEngine::get_video_driver()->getDriverType();
|
||||
lua_pushstring(L, RenderingEngine::getVideoDriverInfo(drivertype).name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMenuCommon::l_irrlicht_device_supports_touch(lua_State *L)
|
||||
{
|
||||
lua_pushboolean(L, RenderingEngine::get_raw_device()->supportsTouchEvents());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ModApiMenuCommon::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(gettext);
|
||||
API_FCT(get_active_driver);
|
||||
API_FCT(irrlicht_device_supports_touch);
|
||||
}
|
||||
|
||||
void ModApiMenuCommon::InitializeAsync(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(gettext);
|
||||
}
|
19
src/script/lua_api/l_menu_common.h
Normal file
19
src/script/lua_api/l_menu_common.h
Normal file
@ -0,0 +1,19 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "l_base.h"
|
||||
|
||||
class ModApiMenuCommon: public ModApiBase
|
||||
{
|
||||
private:
|
||||
static int l_gettext(lua_State *L);
|
||||
static int l_get_active_driver(lua_State *L);
|
||||
static int l_irrlicht_device_supports_touch(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
static void InitializeAsync(lua_State *L, int top);
|
||||
};
|
@ -7,6 +7,7 @@
|
||||
#include "client/client.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "lua_api/l_client.h"
|
||||
#include "lua_api/l_client_common.h"
|
||||
#include "lua_api/l_env.h"
|
||||
#include "lua_api/l_item.h"
|
||||
#include "lua_api/l_itemstackmeta.h"
|
||||
@ -63,6 +64,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
|
||||
ClientSoundHandle::Register(L);
|
||||
|
||||
ModApiUtil::InitializeClient(L, top);
|
||||
ModApiClientCommon::Initialize(L, top);
|
||||
ModApiClient::Initialize(L, top);
|
||||
ModApiItem::InitializeClient(L, top);
|
||||
ModApiStorage::Initialize(L, top);
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "cpp_api/s_client.h"
|
||||
#include "cpp_api/s_client_common.h"
|
||||
#include "cpp_api/s_modchannels.h"
|
||||
#include "cpp_api/s_security.h"
|
||||
|
||||
@ -20,6 +21,7 @@ class Minimap;
|
||||
class ClientScripting:
|
||||
virtual public ScriptApiBase,
|
||||
public ScriptApiSecurity,
|
||||
public ScriptApiClientCommon,
|
||||
public ScriptApiClient,
|
||||
public ScriptApiModChannels
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "lua_api/l_http.h"
|
||||
#include "lua_api/l_mainmenu.h"
|
||||
#include "lua_api/l_mainmenu_sound.h"
|
||||
#include "lua_api/l_menu_common.h"
|
||||
#include "lua_api/l_util.h"
|
||||
#include "lua_api/l_settings.h"
|
||||
#include "log.h"
|
||||
@ -53,12 +54,14 @@ void MainMenuScripting::initializeModApi(lua_State *L, int top)
|
||||
registerLuaClasses(L, top);
|
||||
|
||||
// Initialize mod API modules
|
||||
ModApiMenuCommon::Initialize(L, top);
|
||||
ModApiMainMenu::Initialize(L, top);
|
||||
ModApiUtil::Initialize(L, top);
|
||||
ModApiMainMenuSound::Initialize(L, top);
|
||||
ModApiHttp::Initialize(L, top);
|
||||
|
||||
asyncEngine.registerStateInitializer(registerLuaClasses);
|
||||
asyncEngine.registerStateInitializer(ModApiMenuCommon::InitializeAsync);
|
||||
asyncEngine.registerStateInitializer(ModApiMainMenu::InitializeAsync);
|
||||
asyncEngine.registerStateInitializer(ModApiUtil::InitializeAsync);
|
||||
asyncEngine.registerStateInitializer(ModApiHttp::InitializeAsync);
|
||||
|
@ -40,7 +40,8 @@ public:
|
||||
|
||||
protected:
|
||||
bool checkPathInternal(const std::string &abs_path, bool write_required,
|
||||
bool *write_allowed) override {
|
||||
bool *write_allowed) override
|
||||
{
|
||||
return checkPathAccess(abs_path, write_required, write_allowed);
|
||||
}
|
||||
|
||||
|
53
src/script/scripting_pause_menu.cpp
Normal file
53
src/script/scripting_pause_menu.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
// 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_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
|
||||
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();
|
||||
}
|
32
src/script/scripting_pause_menu.h
Normal file
32
src/script/scripting_pause_menu.h
Normal file
@ -0,0 +1,32 @@
|
||||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2025 grorp
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "cpp_api/s_client_common.h"
|
||||
#include "cpp_api/s_pause_menu.h"
|
||||
#include "cpp_api/s_security.h"
|
||||
#include "scripting_mainmenu.h"
|
||||
|
||||
class PauseMenuScripting:
|
||||
virtual public ScriptApiBase,
|
||||
public ScriptApiPauseMenu,
|
||||
public ScriptApiClientCommon,
|
||||
public ScriptApiSecurity
|
||||
{
|
||||
public:
|
||||
PauseMenuScripting(Client *client);
|
||||
void loadBuiltin();
|
||||
|
||||
protected:
|
||||
bool checkPathInternal(const std::string &abs_path, bool write_required,
|
||||
bool *write_allowed) override
|
||||
{
|
||||
return MainMenuScripting::checkPathAccess(abs_path, write_required, write_allowed);
|
||||
}
|
||||
|
||||
private:
|
||||
void initializeModApi(lua_State *L, int top);
|
||||
};
|
Loading…
Reference in New Issue
Block a user