Dart VM native API - Dart_New

49 views
Skip to first unread message

Michael Francis

unread,
Jun 28, 2017, 12:08:55 PM6/28/17
to Dart Core Development
Not directly related to Core Development but I figured my question would get to the right people here.

I'm embedding the DartVM into an application. In `dart_api.h` there is a method Dart_New which calls a constructor.

/**
 * Invokes a constructor, creating a new object.
 *
 * This function allows hidden constructors (constructors with leading
 * underscores) to be called.
 *
 * \param type Type of object to be constructed.
 * \param constructor_name The name of the constructor to invoke.  Use
 *   Dart_Null() or Dart_EmptyString() to invoke the unnamed constructor.
 *   This name should not include the name of the class.
 * \param number_of_arguments Size of the arguments array.
 * \param arguments An array of arguments to the constructor.
 *
 * \return If the constructor is called and completes successfully,
 *   then the new object. If an error occurs during execution, then an
 *   error handle is returned.
 */
DART_EXPORT Dart_Handle Dart_New(Dart_Handle type,
                                 Dart_Handle constructor_name,
                                 int number_of_arguments,
                                 Dart_Handle* arguments);



How are named parameters handled in this scenario? Are they not supported? Same question for Optional positional parameters.

Michael Francis

unread,
Jun 28, 2017, 1:02:58 PM6/28/17
to Matan Lurey, Dart Core Development
That's what I am currently doing. Was just seeing if there was a way to remove the semi-duplicate code.

On Wed, Jun 28, 2017 at 12:57 PM Matan Lurey <ma...@lurey.org> wrote:
I'm not on the Dart VM team, but I believe they aren't supported. You can workaround this behavior by using an intermediate function:

class MyClass {
  MyClass({String named});

  factory MyClass._intermediate(String named) => new MyClass(named: named);
}

You could then invoke "_intermediate" instead. Hope that helps (or someone more knowledgable chimes in)

--
You received this message because you are subscribed to the Google Groups "Dart Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to core-dev+u...@dartlang.org.

Matan Lurey

unread,
Jun 28, 2017, 1:49:01 PM6/28/17
to Michael Francis, Dart Core Development
I'm not on the Dart VM team, but I believe they aren't supported. You can workaround this behavior by using an intermediate function:

class MyClass {
  MyClass({String named});

  factory MyClass._intermediate(String named) => new MyClass(named: named);
}

You could then invoke "_intermediate" instead. Hope that helps (or someone more knowledgable chimes in)

On Wed, Jun 28, 2017 at 9:08 AM Michael Francis <mfran...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages