File tree Expand file tree Collapse file tree 4 files changed +46
-37
lines changed
generator/binder/templates Expand file tree Collapse file tree 4 files changed +46
-37
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,15 @@ public:
1818 : ScriptClass(ScriptClass::ConstructFromCpp<{{get_wrapper_class_name(class_info)}}>{}),
1919 mResourceHolder(std::move(res)) {}
2020
21+ explicit {{get_wrapper_class_name(class_info)}}(Local<Object > const& thiz, {{class_full_name}}* res)
22+ : ScriptClass(thiz), mResourceHolder(res) {}
23+
24+ explicit {{get_wrapper_class_name(class_info)}}(Local<Object > const& thiz, std::shared_ptr<{{class_full_name}}> res)
25+ : ScriptClass(thiz), mResourceHolder(std::move(res)) {}
26+
27+ explicit {{get_wrapper_class_name(class_info)}}(Local<Object > const& thiz, std::unique_ptr<{{class_full_name}}> res)
28+ : ScriptClass(thiz), mResourceHolder(std::move(res)) {}
29+
2130 [[nodiscard]] static Local<Object > newInstance({{class_full_name}}* res) { return (new {{get_wrapper_class_name(class_info)}}(res))->getScriptObject(); }
2231 [[nodiscard]] static Local<Object > newInstance(std::shared_ptr<{{class_full_name}}> res) { return (new {{get_wrapper_class_name(class_info)}}(std::move(res)))->getScriptObject(); }
2332 [[nodiscard]] static Local<Object > newInstance(std::unique_ptr<{{class_full_name}}> res) { return (new {{get_wrapper_class_name(class_info)}}(std::move(res)))->getScriptObject(); }
@@ -33,3 +42,6 @@ public:
3342public:
3443 static ClassDefine<{{get_wrapper_class_name(class_info)}}> builder;
3544};
45+
46+ // implementation Converter
47+ ImplConverter({{class_full_name}}, {{get_wrapper_class_name(class_info)}});
Original file line number Diff line number Diff line change 33
44#include " detail/StlConverter.hpp"
55
6- // #include "ProjectConverters .hpp" // circular reference, please include manually
6+ #include " ConverterTemplate .hpp" // circular reference, please include manually
77
88
99namespace jse {
Original file line number Diff line number Diff line change 1+ #pragma once
2+ #include " detail/Converter.hpp"
3+
4+
5+ #define ImplConverter (NATIVE_TYPE, WRAPPER_TYPE ) \
6+ namespace detail { \
7+ template <> \
8+ struct Converter <NATIVE_TYPE> { \
9+ static Local<Value> toScript (NATIVE_TYPE* res) { return WRAPPER_TYPE::newInstance (res); } \
10+ static Local<Value> toScript (std::shared_ptr<NATIVE_TYPE> res) { \
11+ return WRAPPER_TYPE::newInstance (std::move (res)); \
12+ } \
13+ static Local<Value> toScript (std::unique_ptr<NATIVE_TYPE> res) { \
14+ return WRAPPER_TYPE::newInstance (std::move (res)); \
15+ } \
16+ static NATIVE_TYPE* toCpp (Local<Value> const & val) { \
17+ if (EngineScope::currentEngine ()->isInstanceOf <WRAPPER_TYPE>(val)) { \
18+ return EngineScope ::currentEngine ()->getNativeInstance <WRAPPER_TYPE>(val)->get (); \
19+ } \
20+ throw script::Exception (" Failed to convert value to " #NATIVE_TYPE); \
21+ } \
22+ }; \
23+ template <> \
24+ struct Converter <WRAPPER_TYPE> { \
25+ static Local<Value> toScript (WRAPPER_TYPE* res) { return res->getScriptObject (); } \
26+ static WRAPPER_TYPE* toCpp (Local<Value> const & val) { \
27+ if (EngineScope::currentEngine ()->isInstanceOf <WRAPPER_TYPE>(val)) { \
28+ return EngineScope ::currentEngine ()->getNativeInstance <WRAPPER_TYPE>(val); \
29+ } \
30+ throw script::Exception (" Failed to convert value to " #WRAPPER_TYPE); \
31+ } \
32+ }; \
33+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments