/* * Create a new IO object */ static int NewIOObject(duk_context* ctx, void* pinCtx, int pinFunc, duk_c_function finalizer) { int idx = duk_push_object(ctx); duk_push_string(ctx, "pin"); duk_dup(ctx, 0); duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); duk_push_string(ctx, AJS_HIDDEN_PROP("ctx")); duk_push_pointer(ctx, pinCtx); duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); duk_push_string(ctx, "pinFunction"); duk_push_int(ctx, pinFunc); duk_def_prop(ctx, idx, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_HAVE_WRITABLE); /* * Callback from when the pin object is garbage collected. */ AJS_RegisterFinalizer(ctx, idx, finalizer); return idx; }
void AJS_RegisterMsgFunctions(AJ_BusAttachment* bus, duk_context* ctx, duk_idx_t ajIdx) { duk_idx_t objIdx; duk_push_c_function(ctx, NativeBroadcastSignal, 2); duk_put_prop_string(ctx, ajIdx, "signal"); duk_push_global_stash(ctx); /* * Push and initialized the peerProto object */ objIdx = duk_push_object(ctx); duk_put_number_list(ctx, objIdx, peer_native_numbers); AJS_PutFunctionList(ctx, objIdx, peer_native_functions, TRUE); /* * Finalizer function called when the object is deleted */ AJS_RegisterFinalizer(ctx, objIdx, NativeServiceObjectFinalizer); /* * Give the object a name */ duk_put_prop_string(ctx, -2, "peerProto"); duk_pop(ctx); }