Skip to content

Commit

Permalink
[unreal] add MakeConstVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieyang committed Oct 18, 2024
1 parent c0025f7 commit cf539a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions unreal/Puerts/Source/JsEnv/Public/ScriptBackend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
::PUERTS_NAMESPACE::PropertyWrapper<PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API, decltype(M), M>::info()
#define MakeVariable(M) MakeProperty(M)
#define MakeReadonlyVariable(M) MakeReadonlyProperty(M)
#define MakeConstVariable(M) \
&(::PUERTS_NAMESPACE::ConstVariableWrapper<PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API, decltype(M), M>::getter), nullptr, \
::PUERTS_NAMESPACE::ConstVariableWrapper<PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API, decltype(M), M>::info()
#define MakeFunction(M, ...) \
[](::PUERTS_NAMESPACE::PUERTS_BINDING_IMPL::API::CallbackInfoType info) \
{ \
Expand Down
19 changes: 19 additions & 0 deletions unreal/Puerts/Source/JsEnv/Public/StaticCall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,25 @@ struct PropertyWrapper<API, Ret*, Variable>
return CTypeInfoImpl<Ret, false>::get();
}
};
template <typename API, typename Ret, Ret Variable>
struct ConstVariableWrapper
{
template <typename T>
using DecayTypeConverter = typename API::template Converter<typename internal::ConverterDecay<T>::type>;

static void getter(typename API::CallbackInfoType info)
{
auto context = API::GetContext(info);
API::SetReturn(info, DecayTypeConverter<Ret>::toScript(context, Variable));
}

static void setter(typename API::CallbackInfoType info) { }

static const CTypeInfo* info()
{
return CTypeInfoImpl<Ret, false>::get();
}
};

template <typename T, typename API, typename RegisterAPI>
class ClassDefineBuilder
Expand Down

0 comments on commit cf539a8

Please sign in to comment.