Merge branch 'add_scripText_to_mwscriptbindings' into 'master'
Some checks failed
Build and test / Ubuntu (push) Has been cancelled
Build and test / MacOS (push) Has been cancelled
Build and test / Read .env file and expose it as output (push) Has been cancelled
Build and test / Windows (2019) (push) Has been cancelled
Build and test / Windows (2022) (push) Has been cancelled

lua - add mwscript bindings to core

See merge request OpenMW/openmw!4517
This commit is contained in:
fallchildren 2025-04-26 06:17:12 +00:00
commit f1ca4d7139
6 changed files with 66 additions and 1 deletions

View file

@ -1,3 +1,8 @@
0.50.0
------
Feature #8320: Add access mwscript source text to lua api
0.49.0 0.49.0
------ ------

View file

@ -60,7 +60,7 @@ add_openmw_dir (mwscript
add_openmw_dir (mwlua add_openmw_dir (mwlua
luamanagerimp object objectlists userdataserializer luaevents engineevents objectvariant luamanagerimp object objectlists userdataserializer luaevents engineevents objectvariant
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings coremwscriptbindings
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker magicbindings factionbindings postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker magicbindings factionbindings
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings

View file

@ -19,6 +19,7 @@
#include "../mwworld/datetimemanager.hpp" #include "../mwworld/datetimemanager.hpp"
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "coremwscriptbindings.hpp"
#include "dialoguebindings.hpp" #include "dialoguebindings.hpp"
#include "factionbindings.hpp" #include "factionbindings.hpp"
#include "luaevents.hpp" #include "luaevents.hpp"
@ -97,6 +98,9 @@ namespace MWLua
api["stats"] api["stats"]
= context.cachePackage("openmw_core_stats", [context]() { return initCoreStatsBindings(context); }); = context.cachePackage("openmw_core_stats", [context]() { return initCoreStatsBindings(context); });
api["mwscripts"]
= context.cachePackage("openmw_core_mwscripts", [context]() { return initCoreMwScriptBindings(context); });
api["factions"] api["factions"]
= context.cachePackage("openmw_core_factions", [context]() { return initCoreFactionBindings(context); }); = context.cachePackage("openmw_core_factions", [context]() { return initCoreFactionBindings(context); });
api["dialogue"] api["dialogue"]

View file

@ -0,0 +1,28 @@
#include "coremwscriptbindings.hpp"
#include <components/esm3/loadscpt.hpp>
#include "../mwworld/esmstore.hpp"
#include "context.hpp"
#include "recordstore.hpp"
namespace MWLua
{
sol::table initCoreMwScriptBindings(const Context& context)
{
sol::state_view lua = context.sol();
sol::table api(lua, sol::create);
auto recordBindingsClass = lua.new_usertype<ESM::Script>("ESM3_Script");
recordBindingsClass[sol::meta_function::to_string]
= [](const ESM::Script& rec) { return "ESM3_Script[" + rec.mId.toDebugString() + "]"; };
recordBindingsClass["id"]
= sol::readonly_property([](const ESM::Script& rec) { return rec.mId.serializeText(); });
recordBindingsClass["text"] = sol::readonly_property([](const ESM::Script& rec) { return rec.mScriptText; });
addRecordFunctionBinding<ESM::Script>(api, context);
return LuaUtil::makeReadOnly(api);
}
}

View file

@ -0,0 +1,13 @@
#ifndef MWLUA_COREMWSCRIPTBINDINGS_H
#define MWLUA_COREMWSCRIPTBINDINGS_H
#include <sol/forward.hpp>
namespace MWLua
{
struct Context;
sol::table initCoreMwScriptBindings(const Context& context);
}
#endif // MWLUA_COREMWSCRIPTBINDINGS_H

View file

@ -1143,4 +1143,19 @@
-- @field #number favouredSkillValue Secondary skill value required to get this rank. -- @field #number favouredSkillValue Secondary skill value required to get this rank.
-- @field #number factionReaction Reaction of faction members if player is in this faction. -- @field #number factionReaction Reaction of faction members if player is in this faction.
--- @{#MWScripts}: MWScripts
-- @field [parent=#core] #MWScript mwscripts
---
-- A read-only list of all @{#MWScriptRecord}s in the world database.
-- @field [parent=#MWScripts] #list<#MWScriptRecord> records
-- @usage local record = core.mwscripts.records['example_recordid']
-- @usage local record = core.mwscripts.records[1]
---
-- MWScript data record
-- @type MWScriptRecord
-- @field #string id MWScript id
-- @field #string text MWScript content
return nil return nil