mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Mainmenu: Move core.on_before_close to s_mainmenu like other callbacks, and doc
This commit is contained in:
parent
2c83c67b7d
commit
4a8f84b259
6 changed files with 31 additions and 20 deletions
|
@ -21,7 +21,6 @@ function check_cache_age(key, max_age)
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.on_before_close()
|
function core.on_before_close()
|
||||||
-- called before the menu is closed, either exit or to join a game
|
|
||||||
cache_settings:write()
|
cache_settings:write()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ Callbacks
|
||||||
* `core.event_handler(event)`
|
* `core.event_handler(event)`
|
||||||
* `event`: `"MenuQuit"`, `"KeyEnter"`, `"ExitButton"`, `"EditBoxEnter"` or
|
* `event`: `"MenuQuit"`, `"KeyEnter"`, `"ExitButton"`, `"EditBoxEnter"` or
|
||||||
`"FullscreenChange"`
|
`"FullscreenChange"`
|
||||||
|
* `core.on_before_close()`: called before the menu is closed, either to exit or
|
||||||
|
to join a game
|
||||||
|
|
||||||
|
|
||||||
Gamedata
|
Gamedata
|
||||||
|
|
|
@ -34,7 +34,7 @@ void ScriptApiMainMenu::handleMainMenuEvent(const std::string &text)
|
||||||
lua_getfield(L, -1, "event_handler");
|
lua_getfield(L, -1, "event_handler");
|
||||||
lua_remove(L, -2); // Remove core
|
lua_remove(L, -2); // Remove core
|
||||||
if (lua_isnil(L, -1)) {
|
if (lua_isnil(L, -1)) {
|
||||||
lua_pop(L, 1); // Pop event_handler
|
lua_pop(L, 2); // Pop event_handler, error handler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
luaL_checktype(L, -1, LUA_TFUNCTION);
|
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||||
|
@ -56,7 +56,7 @@ void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
|
||||||
lua_getfield(L, -1, "button_handler");
|
lua_getfield(L, -1, "button_handler");
|
||||||
lua_remove(L, -2); // Remove core
|
lua_remove(L, -2); // Remove core
|
||||||
if (lua_isnil(L, -1)) {
|
if (lua_isnil(L, -1)) {
|
||||||
lua_pop(L, 1); // Pop button handler
|
lua_pop(L, 2); // Pop button handler, error handler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
luaL_checktype(L, -1, LUA_TFUNCTION);
|
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||||
|
@ -76,3 +76,25 @@ void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
|
||||||
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
|
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
|
||||||
lua_pop(L, 1); // Pop error handler
|
lua_pop(L, 1); // Pop error handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptApiMainMenu::beforeClose()
|
||||||
|
{
|
||||||
|
SCRIPTAPI_PRECHECKHEADER
|
||||||
|
|
||||||
|
int error_handler = PUSH_ERROR_HANDLER(L);
|
||||||
|
|
||||||
|
// Get handler function
|
||||||
|
lua_getglobal(L, "core");
|
||||||
|
lua_getfield(L, -1, "on_before_close");
|
||||||
|
lua_remove(L, -2); // Remove core
|
||||||
|
if (lua_isnil(L, -1)) {
|
||||||
|
lua_pop(L, 2); // Pop callback, error handler
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,4 +27,9 @@ public:
|
||||||
* @param fields data in field format
|
* @param fields data in field format
|
||||||
*/
|
*/
|
||||||
void handleMainMenuButtons(const StringMap &fields);
|
void handleMainMenuButtons(const StringMap &fields);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before the menu is closed, either to exit or to join a game
|
||||||
|
*/
|
||||||
|
void beforeClose();
|
||||||
};
|
};
|
||||||
|
|
|
@ -114,20 +114,6 @@ bool MainMenuScripting::checkPathAccess(const std::string &abs_path, bool write_
|
||||||
return !write_required;
|
return !write_required;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenuScripting::beforeClose()
|
|
||||||
{
|
|
||||||
SCRIPTAPI_PRECHECKHEADER
|
|
||||||
|
|
||||||
int error_handler = PUSH_ERROR_HANDLER(L);
|
|
||||||
|
|
||||||
lua_getglobal(L, "core");
|
|
||||||
lua_getfield(L, -1, "on_before_close");
|
|
||||||
|
|
||||||
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
|
|
||||||
|
|
||||||
lua_pop(L, 2); // Pop core, error handler
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainMenuScripting::step()
|
void MainMenuScripting::step()
|
||||||
{
|
{
|
||||||
asyncEngine.step(getStack());
|
asyncEngine.step(getStack());
|
||||||
|
|
|
@ -24,9 +24,6 @@ public:
|
||||||
// Global step handler to pass back async events
|
// Global step handler to pass back async events
|
||||||
void step();
|
void step();
|
||||||
|
|
||||||
// Calls core.on_before_close()
|
|
||||||
void beforeClose();
|
|
||||||
|
|
||||||
// Pass async events from engine to async threads
|
// Pass async events from engine to async threads
|
||||||
u32 queueAsync(std::string &&serialized_func,
|
u32 queueAsync(std::string &&serialized_func,
|
||||||
std::string &&serialized_param);
|
std::string &&serialized_param);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue