Merge branch 'indexthemoon' into 'master'

Move Lua index helpers to components and make owner.factionRank match other ranks

See merge request OpenMW/openmw!4186
This commit is contained in:
psi29a 2024-06-24 07:06:24 +00:00
commit d3c3d0cf44
16 changed files with 73 additions and 52 deletions

20
components/lua/util.hpp Normal file
View file

@ -0,0 +1,20 @@
#ifndef COMPONENTS_LUA_UTIL_H
#define COMPONENTS_LUA_UTIL_H
#include <cstdint>
namespace LuaUtil
{
// Lua arrays index from 1
constexpr inline std::int64_t fromLuaIndex(std::int64_t i)
{
return i - 1;
}
constexpr inline std::int64_t toLuaIndex(std::int64_t i)
{
return i + 1;
}
}
#endif

View file

@ -10,6 +10,7 @@
#include <components/misc/mathutil.hpp>
#include "luastate.hpp"
#include "util.hpp"
#include "shapes/box.hpp"
@ -143,7 +144,7 @@ namespace LuaUtil
sol::table table(lua, sol::create);
const auto vertices = b.vertices();
for (size_t i = 0; i < vertices.size(); ++i)
table[i + 1] = vertices[i];
table[toLuaIndex(i)] = vertices[i];
return table;
});
boxType[sol::meta_function::equal_to] = [](const Box& a, const Box& b) { return a == b; };