Skip to content

Commit

Permalink
Merge branch 'fix_lua_48' into 'openmw-48'
Browse files Browse the repository at this point in the history
Merge !2661, !2687, !2733, !2770, !2774 to openmw-48 (fixes #7128)

See merge request OpenMW/openmw!2778
  • Loading branch information
psi29a committed Feb 28, 2023
2 parents 15236fa + ae23daf commit 2f6a809
Show file tree
Hide file tree
Showing 25 changed files with 551 additions and 384 deletions.
2 changes: 1 addition & 1 deletion apps/openmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ add_openmw_dir (mwscript

add_openmw_dir (mwlua
luamanagerimp object worldview userdataserializer eventqueue
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings
luabindings localscripts playerscripts objectbindings cellbindings
camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings
types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book types/lockpick types/probe types/apparatus types/potion types/ingredient types/misc types/repair
)
Expand Down
69 changes: 0 additions & 69 deletions apps/openmw/mwlua/asyncbindings.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions apps/openmw/mwlua/luabindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ namespace MWLua
void initCellBindingsForLocalScripts(const Context&);
void initCellBindingsForGlobalScripts(const Context&);

// Implemented in asyncbindings.cpp
struct AsyncPackageId
{
LuaUtil::ScriptsContainer* mContainer;
int mScriptId;
sol::table mHiddenData;
};
sol::function getAsyncPackageInitializer(const Context&);

// Implemented in camerabindings.cpp
sol::table initCameraPackage(const Context&);

Expand Down
6 changes: 5 additions & 1 deletion apps/openmw/mwlua/luamanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <components/settings/settings.hpp>

#include <components/lua/asyncpackage.hpp>
#include <components/lua/utilpackage.hpp>

#include <components/lua_ui/util.hpp>
Expand Down Expand Up @@ -86,7 +87,10 @@ namespace MWLua
LocalScripts::initializeSelfPackage(localContext);
LuaUtil::LuaStorage::initLuaBindings(mLua.sol());

mLua.addCommonPackage("openmw.async", getAsyncPackageInitializer(context));
mLua.addCommonPackage("openmw.async",
LuaUtil::getAsyncPackageInitializer(
mLua.sol(), [this] { return mWorldView.getSimulationTime(); },
[this] { return mWorldView.getGameTime(); }));
mLua.addCommonPackage("openmw.util", LuaUtil::initUtilPackage(mLua.sol()));
mLua.addCommonPackage("openmw.core", initCorePackage(context));
mLua.addCommonPackage("openmw.types", initTypesPackage(context));
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwlua/nearbybindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ namespace MWLua
MWBase::Environment::get().getWorld()->castRenderingRay(res, from, to, false, false);
return res;
};
api["asyncCastRenderingRay"] = [context](const LuaUtil::Callback& callback, const osg::Vec3f& from,
const osg::Vec3f& to) {
context.mLuaManager->addAction([context, callback, from, to] {
api["asyncCastRenderingRay"] = [context](
const sol::table& callback, const osg::Vec3f& from, const osg::Vec3f& to) {
context.mLuaManager->addAction([context, callback = LuaUtil::Callback::fromLua(callback), from, to] {
MWPhysics::RayCastingResult res;
MWBase::Environment::get().getWorld()->castRenderingRay(res, from, to, false, false);
context.mLuaManager->queueCallback(callback, sol::main_object(context.mLua->sol(), sol::in_place, res));
Expand Down
71 changes: 2 additions & 69 deletions apps/openmw/mwlua/uibindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,69 +89,6 @@ namespace MWLua

sol::table initUserInterfacePackage(const Context& context)
{
auto uiContent = context.mLua->sol().new_usertype<LuaUi::Content>("UiContent");
uiContent[sol::meta_function::length] = [](const LuaUi::Content& content)
{
return content.size();
};
uiContent[sol::meta_function::index] = sol::overload(
[](const LuaUi::Content& content, size_t index)
{
return content.at(fromLuaIndex(index));
},
[](const LuaUi::Content& content, std::string_view name)
{
return content.at(name);
});
uiContent[sol::meta_function::new_index] = sol::overload(
[](LuaUi::Content& content, size_t index, const sol::table& table)
{
content.assign(fromLuaIndex(index), table);
},
[](LuaUi::Content& content, size_t index, sol::nil_t nil)
{
content.remove(fromLuaIndex(index));
},
[](LuaUi::Content& content, std::string_view name, const sol::table& table)
{
content.assign(name, table);
},
[](LuaUi::Content& content, std::string_view name, sol::nil_t nil)
{
content.remove(name);
});
uiContent["insert"] = [](LuaUi::Content& content, size_t index, const sol::table& table)
{
content.insert(fromLuaIndex(index), table);
};
uiContent["add"] = [](LuaUi::Content& content, const sol::table& table)
{
content.insert(content.size(), table);
};
uiContent["indexOf"] = [](LuaUi::Content& content, const sol::table& table) -> sol::optional<size_t>
{
size_t index = content.indexOf(table);
if (index < content.size())
return toLuaIndex(index);
else
return sol::nullopt;
};
{
auto pairs = [](LuaUi::Content& content)
{
auto next = [](LuaUi::Content& content, size_t i) -> sol::optional<std::tuple<size_t, sol::table>>
{
if (i < content.size())
return std::make_tuple(i + 1, content.at(i));
else
return sol::nullopt;
};
return std::make_tuple(next, content, 0);
};
uiContent[sol::meta_function::ipairs] = pairs;
uiContent[sol::meta_function::pairs] = pairs;
}

auto element = context.mLua->sol().new_usertype<LuaUi::Element>("Element");
element["layout"] = sol::property(
[](LuaUi::Element& element)
Expand Down Expand Up @@ -210,12 +147,8 @@ namespace MWLua
luaManager->addAction([wm, obj=obj.as<LObject>()]{ wm->setConsoleSelectedObject(obj.ptr()); });
}
};
api["content"] = [](const sol::table& table)
{
return LuaUi::Content(table);
};
api["create"] = [context](const sol::table& layout)
{
api["content"] = LuaUi::loadContentConstructor(context.mLua);
api["create"] = [context](const sol::table& layout) {
auto element = LuaUi::Element::make(layout);
context.mLuaManager->addAction(std::make_unique<UiAction>(UiAction::CREATE, element, context.mLua));
return element;
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw_test_suite/lua/test_async.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "gmock/gmock.h"
#include <gtest/gtest.h>

#include <components/lua/asyncpackage.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/scriptscontainer.hpp>

#include "../testing_util.hpp"

Expand Down
1 change: 1 addition & 0 deletions apps/openmw_test_suite/lua/test_scriptscontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <components/esm/luascripts.hpp>

#include <components/lua/asyncpackage.hpp>
#include <components/lua/luastate.hpp>
#include <components/lua/scriptscontainer.hpp>

Expand Down
21 changes: 10 additions & 11 deletions apps/openmw_test_suite/lua/test_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>

#include <components/lua/scriptscontainer.hpp>
#include <components/lua/asyncpackage.hpp>
#include <components/lua/storage.hpp>

namespace
Expand All @@ -24,17 +24,16 @@ namespace
LuaUtil::LuaStorage storage(mLua);

std::vector<std::string> callbackCalls;
LuaUtil::Callback callback{
sol::make_object(mLua, [&](const std::string& section, const sol::optional<std::string>& key)
{
if (key)
callbackCalls.push_back(section + "_" + *key);
else
callbackCalls.push_back(section + "_*");
}),
sol::table(mLua, sol::create)
sol::table callbackHiddenData(mLua, sol::create);
callbackHiddenData[LuaUtil::ScriptsContainer::sScriptIdKey] = LuaUtil::ScriptsContainer::ScriptId{};
sol::table callback(mLua, sol::create);
callback[1] = [&](const std::string& section, const sol::optional<std::string>& key) {
if (key)
callbackCalls.push_back(section + "_" + *key);
else
callbackCalls.push_back(section + "_*");
};
callback.mHiddenData[LuaUtil::ScriptsContainer::sScriptIdKey] = "fakeId";
callback[2] = LuaUtil::AsyncPackageId{ nullptr, 0, callbackHiddenData };

mLua["mutable"] = storage.getMutableSection("test");
mLua["ro"] = storage.getReadOnlySection("test");
Expand Down
Loading

0 comments on commit 2f6a809

Please sign in to comment.