MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / call_native_constructor

Function call_native_constructor

Source/Utils/dukglue/detail_constructor.h:10–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9 template<bool managed, typename Cls, typename... Ts>
10 static duk_ret_t call_native_constructor(duk_context* ctx)
11 {
12 if (!duk_is_constructor_call(ctx)) {
13 duk_error(ctx, DUK_RET_TYPE_ERROR, "Constructor must be called with new T().");
14 return DUK_RET_TYPE_ERROR;
15 }
16
17 // construct the new instance
18 auto constructor_args = dukglue::detail::get_stack_values<Ts...>(ctx);
19 Cls* obj = dukglue::detail::apply_constructor<Cls>(std::move(constructor_args));
20
21 duk_push_this(ctx);
22
23 // make the new script object keep the pointer to the new object instance
24 duk_push_pointer(ctx, obj);
25 duk_put_prop_string(ctx, -2, "\xFF" "obj_ptr");
26
27 // register it
28 if (!managed)
29 dukglue::detail::RefManager::register_native_object(ctx, obj);
30
31 duk_pop(ctx); // pop this
32
33 return 0;
34 }
35
36 template <typename Cls>
37 static duk_ret_t managed_finalizer(duk_context* ctx)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected