2024-06-18 19:32:16 +00:00
|
|
|
#ifndef COMPONENTS_LUA_UTIL_H
|
|
|
|
#define COMPONENTS_LUA_UTIL_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
2024-07-07 11:58:34 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <sol/sol.hpp>
|
|
|
|
|
|
|
|
#include <components/esm/refid.hpp>
|
2024-06-18 19:32:16 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-07-07 11:58:34 +00:00
|
|
|
|
|
|
|
inline sol::optional<std::string> serializeRefId(ESM::RefId id)
|
|
|
|
{
|
|
|
|
if (id.empty())
|
|
|
|
return sol::nullopt;
|
|
|
|
return id.serializeText();
|
|
|
|
}
|
2024-06-18 19:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|