1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-23 19:20:56 +00:00

Merge branch 'lua_quit' into 'master'

Lua command `core.quit`

Closes #5936

See merge request OpenMW/openmw!1090
This commit is contained in:
Petr Mikheev 2021-08-04 17:16:24 +00:00
commit 10d100f205
3 changed files with 15 additions and 2 deletions

View File

@ -5,6 +5,8 @@
#include <components/lua/luastate.hpp>
#include <components/queries/luabindings.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/statemanager.hpp"
#include "../mwworld/inventorystore.hpp"
#include "eventqueue.hpp"
@ -31,7 +33,13 @@ namespace MWLua
{
auto* lua = context.mLua;
sol::table api(lua->sol(), sol::create);
api["API_REVISION"] = 2;
api["API_REVISION"] = 3;
api["quit"] = [lua]()
{
std::string traceback = lua->sol()["debug"]["traceback"]().get<std::string>();
Log(Debug::Warning) << "Quit requested by a Lua script.\n" << traceback;
MWBase::Environment::get().getStateManager()->requestQuit();
};
api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData)
{
context.mGlobalEventQueue->push_back({std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer)});

View File

@ -24,7 +24,8 @@ namespace LuaUtil
LuaState::LuaState(const VFS::Manager* vfs) : mVFS(vfs)
{
mLua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::math, sol::lib::string, sol::lib::table);
mLua.open_libraries(sol::lib::base, sol::lib::coroutine, sol::lib::math,
sol::lib::string, sol::lib::table, sol::lib::debug);
mLua["math"]["randomseed"](static_cast<unsigned>(std::time(nullptr)));
mLua["math"]["randomseed"] = sol::nil;

View File

@ -10,6 +10,10 @@
-- The revision of OpenMW Lua API. It is an integer that is incremented every time the API is changed.
-- @field [parent=#core] #number API_REVISION
-------------------------------------------------------------------------------
-- Terminates the game and quits to the OS. Should be used only for testing purposes.
-- @function [parent=#core] quit
-------------------------------------------------------------------------------
-- Send an event to global scripts.
-- @function [parent=#core] sendGlobalEvent