Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
946 B · 39 lines
C++
at master
12345678910111213141516171819202122232425262728293031323334353637383940#ifndef COMPONENTS_LUA_UTIL_H#define COMPONENTS_LUA_UTIL_H
#include <chrono>#include <cstdint>
#include <sol/sol.hpp>
#include <components/esm/refid.hpp>
namespace LuaUtil{ inline double getRealTime() { return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count(); }
// 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 stringsinline int sol_lua_push(sol::types<ESM::RefId>, lua_State* state, const ESM::RefId& id){ if (id.empty()) return sol::stack::push(state, sol::lua_nil); return sol::stack::push(state, id.serializeText());}
#endif