Skip to content

Commit

Permalink
Merge branch 'master' into dev/fix_extensible_class_static_property
Browse files Browse the repository at this point in the history
  • Loading branch information
kunitoki committed Sep 30, 2023
2 parents e18afd8 + f8554d4 commit b40c42b
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 62 deletions.
71 changes: 41 additions & 30 deletions Distribution/LuaBridge/LuaBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8306,17 +8306,21 @@ class Registrar
{
}

Registrar(const Registrar& rhs)
Registrar(const Registrar& rhs) = delete;

Registrar(Registrar&& rhs)
: L(rhs.L)
, m_stackSize(std::exchange(rhs.m_stackSize, 0))
, m_skipStackPops(std::exchange(rhs.m_skipStackPops, 0))
{
}

Registrar& operator=(const Registrar& rhs)
Registrar& operator=(const Registrar& rhs) = delete;

Registrar& operator=(Registrar&& rhs)
{
m_stackSize = rhs.m_stackSize;
m_skipStackPops = rhs.m_skipStackPops;
m_stackSize = std::exchange(rhs.m_stackSize, 0);
m_skipStackPops = std::exchange(rhs.m_skipStackPops, 0);

return *this;
}
Expand All @@ -8341,8 +8345,8 @@ class Registrar
}

lua_State* const L = nullptr;
int mutable m_stackSize = 0;
int mutable m_skipStackPops = 0;
int m_stackSize = 0;
int m_skipStackPops = 0;
};

}
Expand Down Expand Up @@ -8384,8 +8388,8 @@ class Namespace : public detail::Registrar
class ClassBase : public detail::Registrar
{
public:
explicit ClassBase(Namespace& parent)
: Registrar(parent)
explicit ClassBase(Namespace parent)
: Registrar(std::move(parent))
{
}

Expand Down Expand Up @@ -8488,8 +8492,8 @@ class Namespace : public detail::Registrar
{
public:

Class(const char* name, Namespace& parent, Options options)
: ClassBase(parent)
Class(const char* name, Namespace parent, Options options)
: ClassBase(std::move(parent))
{
LUABRIDGE_ASSERT(name != nullptr);
LUABRIDGE_ASSERT(lua_istable(L, -1));
Expand Down Expand Up @@ -8542,6 +8546,10 @@ class Namespace : public detail::Registrar
LUABRIDGE_ASSERT(lua_istable(L, -1));
++m_stackSize;

lua_getmetatable(L, -1);
lua_insert(L, -2);
lua_pop(L, 1);

lua_rawgetp(L, LUA_REGISTRYINDEX, detail::getConstRegistryKey<T>());
lua_insert(L, -2);
++m_stackSize;
Expand All @@ -8552,8 +8560,8 @@ class Namespace : public detail::Registrar
}
}

Class(const char* name, Namespace& parent, const void* const staticKey, Options options)
: ClassBase(parent)
Class(const char* name, Namespace parent, const void* const staticKey, Options options)
: ClassBase(std::move(parent))
{
LUABRIDGE_ASSERT(name != nullptr);
LUABRIDGE_ASSERT(lua_istable(L, -1));
Expand Down Expand Up @@ -8622,7 +8630,8 @@ class Namespace : public detail::Registrar

m_stackSize -= 3;
lua_pop(L, 3);
return Namespace(*this);

return Namespace(std::move(*this));
}

template <class U, class = std::enable_if_t<std::is_base_of_v<U, LuaRef> || !std::is_invocable_v<U>>>
Expand Down Expand Up @@ -9437,8 +9446,8 @@ class Namespace : public detail::Registrar
class Table : public detail::Registrar
{
public:
explicit Table(const char* name, Namespace& parent)
: Registrar(parent)
explicit Table(const char* name, Namespace parent)
: Registrar(std::move(parent))
{
lua_newtable(L);
lua_pushvalue(L, -1);
Expand Down Expand Up @@ -9489,7 +9498,8 @@ class Namespace : public detail::Registrar

m_stackSize -= 2;
lua_pop(L, 2);
return Namespace(*this);

return Namespace(std::move(*this));
}
};

Expand Down Expand Up @@ -9533,8 +9543,8 @@ class Namespace : public detail::Registrar
++m_stackSize;
}

Namespace(const char* name, Namespace& parent, Options options)
: Registrar(parent)
Namespace(const char* name, Namespace parent, Options options)
: Registrar(std::move(parent))
{
LUABRIDGE_ASSERT(name != nullptr);
LUABRIDGE_ASSERT(lua_istable(L, -1));
Expand Down Expand Up @@ -9575,13 +9585,13 @@ class Namespace : public detail::Registrar
++m_stackSize;
}

explicit Namespace(ClassBase& child)
: Registrar(child)
explicit Namespace(ClassBase child)
: Registrar(std::move(child))
{
}

explicit Namespace(Table& child)
: Registrar(child)
explicit Namespace(Table child)
: Registrar(std::move(child))
{
}

Expand All @@ -9602,7 +9612,7 @@ class Namespace : public detail::Registrar
Namespace beginNamespace(const char* name, Options options = defaultOptions)
{
assertIsActive();
return Namespace(name, *this, options);
return Namespace(name, std::move(*this), options);
}

Namespace endNamespace()
Expand All @@ -9611,13 +9621,14 @@ class Namespace : public detail::Registrar
{
throw_or_assert<std::logic_error>("endNamespace() called on global namespace");

return Namespace(*this);
return Namespace(std::move(*this));
}

LUABRIDGE_ASSERT(m_stackSize > 1);
--m_stackSize;
lua_pop(L, 1);
return Namespace(*this);

return Namespace(std::move(*this));
}

template <class T>
Expand Down Expand Up @@ -9891,21 +9902,21 @@ class Namespace : public detail::Registrar
Table beginTable(const char* name)
{
assertIsActive();
return Table(name, *this);
return Table(name, std::move(*this));
}

template <class T>
Class<T> beginClass(const char* name, Options options = defaultOptions)
{
assertIsActive();
return Class<T>(name, *this, options);
return Class<T>(name, std::move(*this), options);
}

template <class Derived, class Base>
Class<Derived> deriveClass(const char* name, Options options = defaultOptions)
{
assertIsActive();
return Class<Derived>(name, *this, detail::getStaticRegistryKey<Base>(), options);
return Class<Derived>(name, std::move(*this), detail::getStaticRegistryKey<Base>(), options);
}
};

Expand Down Expand Up @@ -10157,7 +10168,7 @@ struct Stack<std::set<K>>
[[nodiscard]] static TypeResult<Type> get(lua_State* L, int index)
{
if (!lua_istable(L, index))
return makeUnexpected(makeErrorCode(ErrorCode::InvalidTypeCast));
return makeErrorCode(ErrorCode::InvalidTypeCast);

const StackRestore stackRestore(L);

Expand All @@ -10170,7 +10181,7 @@ struct Stack<std::set<K>>
{
auto item = Stack<K>::get(L, -1);
if (! item)
return makeUnexpected(makeErrorCode(ErrorCode::InvalidTypeCast));
return makeErrorCode(ErrorCode::InvalidTypeCast);

set.emplace(*item);
lua_pop(L, 1);
Expand Down
4 changes: 2 additions & 2 deletions Source/LuaBridge/Set.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Stack<std::set<K>>
[[nodiscard]] static TypeResult<Type> get(lua_State* L, int index)
{
if (!lua_istable(L, index))
return makeUnexpected(makeErrorCode(ErrorCode::InvalidTypeCast));
return makeErrorCode(ErrorCode::InvalidTypeCast);

const StackRestore stackRestore(L);

Expand All @@ -62,7 +62,7 @@ struct Stack<std::set<K>>
{
auto item = Stack<K>::get(L, -1);
if (! item)
return makeUnexpected(makeErrorCode(ErrorCode::InvalidTypeCast));
return makeErrorCode(ErrorCode::InvalidTypeCast);

set.emplace(*item);
lua_pop(L, 1);
Expand Down
Loading

0 comments on commit b40c42b

Please sign in to comment.