mirror of
https://github.com/OpenMW/openmw.git
synced 2025-11-10 11:26:39 +00:00
Implement sol_lua_push for ESM::RefId to automatically convert empty RefIds to nil in Lua. This fixes cell.region and cell.worldSpaceId returning empty strings, and applies the same pattern consistently across all Lua bindings. Removes LuaUtil::serializeRefId as it's no longer needed. Fixes #8718
34 lines
No EOL
781 B
C++
34 lines
No EOL
781 B
C++
#ifndef COMPONENTS_LUA_UTIL_H
|
|
#define COMPONENTS_LUA_UTIL_H
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include <sol/sol.hpp>
|
|
|
|
#include <components/esm/refid.hpp>
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
// ADL-based customization point for sol2 to automatically convert ESM::RefId
|
|
// Empty RefIds are converted to nil, non-empty ones are serialized to strings
|
|
inline int sol_lua_push(sol::types<ESM::RefId>, lua_State* L, const ESM::RefId& id)
|
|
{
|
|
if (id.empty())
|
|
return sol::stack::push(L, sol::lua_nil);
|
|
return sol::stack::push(L, id.serializeText());
|
|
}
|
|
|
|
#endif |