Skip to content

Commit

Permalink
Update luatype_boost_optional.h
Browse files Browse the repository at this point in the history
  • Loading branch information
shewer authored Oct 24, 2023
1 parent c833bf5 commit e6b4ffb
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/lib/luatype_boost_optional.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@
#define LUATYPE_BOOST_OPTIONAL_H

#include "lua_templates.h"
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
#include <optional>
#else
#include <boost/optional.hpp>
#endif // C++17

namespace ns {
#if __cplusplus >= 201703L || _MSVC_LANG >= 201703L
using std::optional;

#else
using boost::optional;

#endif // C++17


template<typename T>
struct LuaType<boost::optional<T>> {
static void pushdata(lua_State *L, boost::optional<T> o) {
struct LuaType<ns::optional<T>> {
static void pushdata(lua_State *L, ns::optional<T> o) {
if (o)
LuaType<T>::pushdata(L, *o);
else
lua_pushnil(L);
}

static boost::optional<T> &todata(lua_State *L, int i, C_State *C) {
static ns::optional<T> &todata(lua_State *L, int i, C_State *C) {
if (lua_type(L, i) == LUA_TNIL)
return C->alloc<boost::optional<T>>();
return C->alloc<ns::optional<T>>();
else
return C->alloc<boost::optional<T>>(LuaType<T>::todata(L, i, C));
return C->alloc<ns::optional<T>>(LuaType<T>::todata(L, i, C));
}
};

Expand Down

0 comments on commit e6b4ffb

Please sign in to comment.