Lua command `core.quit`

pull/3097/head
Petr Mikheev 3 years ago
parent 8a14daaac7
commit a94072243b

@ -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)});

@ -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;

@ -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

Loading…
Cancel
Save