| 22 | |
| 23 | template<MethodType methodToCall> |
| 24 | struct MethodCompiletime |
| 25 | { |
| 26 | static duk_ret_t call_native_method(duk_context* ctx) |
| 27 | { |
| 28 | // get this.obj_ptr |
| 29 | duk_push_this(ctx); |
| 30 | duk_get_prop_string(ctx, -1, "\xFF" "obj_ptr"); |
| 31 | void* obj_void = duk_require_pointer(ctx, -1); |
| 32 | if (obj_void == nullptr) { |
| 33 | duk_error(ctx, DUK_RET_REFERENCE_ERROR, "Native object missing."); |
| 34 | return DUK_RET_REFERENCE_ERROR; |
| 35 | } |
| 36 | |
| 37 | duk_pop_2(ctx); |
| 38 | |
| 39 | // (should always be valid unless someone is intentionally messing with this.obj_ptr...) |
| 40 | Cls* obj = static_cast<Cls*>(obj_void); |
| 41 | |
| 42 | // read arguments and call function |
| 43 | auto bakedArgs = dukglue::detail::get_stack_values<Ts...>(ctx); |
| 44 | actually_call(ctx, obj, bakedArgs); |
| 45 | return std::is_void<RetType>::value ? 0 : 1; |
| 46 | } |
| 47 | |
| 48 | // this mess is to support functions with void return values |
| 49 | template<typename Dummy = RetType, typename... BakedTs> |
| 50 | static typename std::enable_if<!std::is_void<Dummy>::value>::type actually_call(duk_context* ctx, Cls* obj, const std::tuple<BakedTs...>& args) |
| 51 | { |
| 52 | // ArgStorage has some static_asserts in it that validate value types, |
| 53 | // so we typedef it to force ArgStorage<RetType> to compile and run the asserts |
| 54 | typedef typename dukglue::types::ArgStorage<RetType>::type ValidateReturnType; |
| 55 | |
| 56 | RetType return_val = dukglue::detail::apply_method<Cls, RetType, Ts...>(methodToCall, obj, args); |
| 57 | |
| 58 | using namespace dukglue::types; |
| 59 | DukType<typename Bare<RetType>::type>::template push<RetType>(ctx, std::move(return_val)); |
| 60 | } |
| 61 | |
| 62 | template<typename Dummy = RetType, typename... BakedTs> |
| 63 | static typename std::enable_if<std::is_void<Dummy>::value>::type actually_call(duk_context* ctx, Cls* obj, const std::tuple<BakedTs...>& args) |
| 64 | { |
| 65 | dukglue::detail::apply_method(methodToCall, obj, args); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | struct MethodRuntime |
nothing calls this directly
no outgoing calls
no test coverage detected