File: util.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (32 lines) | stat: -rw-r--r-- 587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#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;
    }

    inline sol::optional<std::string> serializeRefId(ESM::RefId id)
    {
        if (id.empty())
            return sol::nullopt;
        return id.serializeText();
    }
}

#endif