Add support for class constructor parameters
This commit is contained in:
parent
d3ad818b8e
commit
996a089185
1 changed files with 18 additions and 3 deletions
|
@ -42,6 +42,12 @@ namespace wren {
|
|||
std::same_as<std::remove_cv_t<T>, ModuleAndName>;
|
||||
};
|
||||
#endif
|
||||
|
||||
template <typename T, int... Indices, typename... Args>
|
||||
inline void construct_foreign_class (
|
||||
std::integer_sequence<int, Indices...>,
|
||||
void* memory
|
||||
);
|
||||
} //namespace detail
|
||||
|
||||
#if __cpp_concepts >= 201907
|
||||
|
@ -63,7 +69,7 @@ namespace wren {
|
|||
template <typename R, std::size_t N, typename... Args>
|
||||
R call (VM& vm, const ModuleAndName& object, const char (&method)[N], const Args&... args);
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename... Args>
|
||||
foreign_class_t make_foreign_class();
|
||||
|
||||
template <typename T, typename... Args>
|
||||
|
@ -198,6 +204,15 @@ namespace wren {
|
|||
|
||||
template <typename T, typename R, typename... Args, R(T::*Method)(Args...)> struct MakeMethodBindable<Method> : MakeMethodBindableConstNonConst<T, R, Method, Args...> {};
|
||||
template <typename T, typename R, typename... Args, R(T::*Method)(Args...)const> struct MakeMethodBindable<Method> : MakeMethodBindableConstNonConst<T, R, Method, Args...> {};
|
||||
|
||||
template <typename T, typename... Args, int... Indices>
|
||||
inline void construct_foreign_class (
|
||||
std::integer_sequence<int, Indices...>,
|
||||
VM& vm,
|
||||
void* memory
|
||||
) {
|
||||
new(memory) T{get<Args>(vm, Indices + 1)...};
|
||||
}
|
||||
} //namespace detail
|
||||
|
||||
#if __cpp_concepts >= 201907
|
||||
|
@ -299,12 +314,12 @@ namespace wren {
|
|||
return call<R, N, Args...>(vm, obj_handle, method, args...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template <typename T, typename... Args>
|
||||
inline foreign_class_t make_foreign_class() {
|
||||
foreign_class_t ret;
|
||||
ret.allocate = [](VM& vm) {
|
||||
void* const mem = vm.set_slot_new_foreign(0, 0, sizeof(T));
|
||||
new(mem) T;
|
||||
detail::construct_foreign_class<T, Args...>(std::make_integer_sequence<int, sizeof...(Args)>{}, vm, mem);
|
||||
};
|
||||
ret.finalize = [](void* mem) {
|
||||
const auto cale = static_cast<T*>(mem);
|
||||
|
|
Loading…
Reference in a new issue