Skip to content

Commit

Permalink
Update shared lib
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Nov 1, 2023
1 parent d505897 commit 0959830
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Core/Raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RawVFunc<A, R (C::*)(Args...)> : public RawBase

constexpr RawVFunc() = default;

R operator()(C* aContext, Args&&... aArgs) const
R operator()(C* aContext, Args... aArgs) const
{
auto vft = *reinterpret_cast<uintptr_t*>(aContext);
auto callable = *reinterpret_cast<Callable*>(vft + offset);
Expand Down
9 changes: 9 additions & 0 deletions lib/Red/Specializations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ struct std::hash<RED4ext::ResourcePath>
}
};

template<>
struct std::hash<RED4ext::NodeRef>
{
std::size_t operator()(RED4ext::NodeRef aKey) const
{
return aKey.hash;
}
};

template<typename T>
requires std::is_class_v<T> && std::is_convertible_v<T, size_t> && Red::Detail::HasGeneratedTypeName<T>
struct std::hash<T>
Expand Down
10 changes: 6 additions & 4 deletions lib/Red/TypeInfo/Invocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ inline bool CallFunctionWithArgs(Red::CStackFrame* aFrame, CBaseFunction* aFunc,
const auto& param = aFunc->params[i];
const auto& arg = stack.args[i];

if (!arg.value && !param->flags.isOptional)
if (arg.value)
{
return false;
if (!IsCompatible(param->type, arg.type, arg.value))
{
return false;
}
}

if (!IsCompatible(param->type, arg.type, arg.value))
else if (!param->flags.isOptional)
{
return false;
}
Expand Down
19 changes: 19 additions & 0 deletions lib/Red/TypeInfo/Resolving.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,25 @@ inline void RegisterPendingTypes()
CRTTISystem::Get()->GetType("Int32");
}

template<typename T, typename U = ISerializable>
inline const Handle<T>& Cast(const Handle<U>& aObject)
{
static const Handle<T> s_null;
return aObject->GetType()->IsA(Red::GetClass<T>()) ? *reinterpret_cast<const Handle<T>*>(&aObject) : s_null;
}

template<typename T>
inline bool IsInstanceOf(CClass* aType)
{
return aType->IsA(Red::GetClass<T>());
}

template<typename T>
inline bool IsInstanceOf(ISerializable* aObject)
{
return aObject->GetType()->IsA(Red::GetClass<T>());
}

inline bool IsCompatible(CBaseRTTIType* aLhsType, CBaseRTTIType* aRhsType)
{
if (aLhsType != aRhsType)
Expand Down

0 comments on commit 0959830

Please sign in to comment.