Providing implementation for the functions and methods declared external

589 views
Skip to first unread message

Jirka Daněk

unread,
Jan 31, 2014, 7:34:32 AM1/31/14
to mi...@dartlang.org
The spec says "An external function is connected to its body by an implementation specific mechanism." I was unable to find out how to implement an external function from Dart. Actually, I found nothing about how to implement external function.

As an example, imagine having a library that contains abstract class like this

library file;
abstract class File {
  external factory File(String identifier); // or maybe
  external static Future<File> open(String identifier);
  … // read, write, abstract methods like that
}

if I wish to implement that external functions from a different library, what can I do?

library my_cached_file;
???
 One more question. External and native are two different keywords, yes?

Filipe Morgado

unread,
Jan 31, 2014, 7:50:31 AM1/31/14
to mi...@dartlang.org
Hi,

I don't know if you want to override existing external functions, or create your own.

I don't believe it's possible to override external functions. You may need to wrap different implementations behind a common interface.

I never tried to extend the Dart VM (create my own externals), but if I would, I'd start by looking at the following links:

I don't know if the content is accurate or up-to-date.

Hope it helps :)

Lasse R.H. Nielsen

unread,
Jan 31, 2014, 7:55:18 AM1/31/14
to mi...@dartlang.org
You can't create external functions as a Dart programmer.
External functions are a way for the Dart implementations (the VM and Dart2js) to inject their own implementations of a method into a shared platform library.
It's in the specification in order to make the platform libraries syntactically correct Dart, but the "patch" functionality that we use to specify the implementation isn't accessible.

The word "native" isn't a keyword in Dart. It is used internally in some VM files for the VM to make their Dart functions have C++ implementations, but it is not valid Dart syntax.
The built-in identifier "external" can only really be used inside platform libraries.

/L


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.



--
Lasse R.H. Nielsen - l...@google.com  
'Faith without judgement merely degrades the spirit divine'
Google Denmark ApS - Frederiksborggade 20B, 1 sal - 1360 København K - Denmark - CVR nr. 28 86 69 84

Jirka Daněk

unread,
Jan 31, 2014, 8:36:07 AM1/31/14
to mi...@dartlang.org
On Friday, January 31, 2014 1:50:31 PM UTC+1, Filipe Morgado wrote:
Hi,

I don't know if you want to override existing external functions, or create your own.

I thought I would get more to the point answers if I did not say what I want to do. I want to do the first think -- reimplement some parts of the dart:io library in Dart+dart:js calls while using as much of the original code as possible and keeping the API exactly the same to allow drop and plug replacement. I thought it would be fantastic if I could just copy over some of the files from dart:io and build around them without making any modification to it. Seems it is not always possible.
 
I don't believe it's possible to override extern functions. You may need to wrap different implementations behind a common interface.

I will do that. That is what we have classes for in Dart anyway ;-)

I will have problems when there is a dart:io method that is synchronous and my javascript replacement must be called asynchronoustly, but I hope it will work out well at the end.
 
I never tried to extend the Dart VM (create my own externals), but if I would, I'd start by looking at the following links:

 
I don't know if the content is accurate or up-to-date.

The approach described in synchronous part of the tutorial as of now still works. I have an example that encrypts and decrypts some data by calling libsodium this way. That is the approach that uses the native not-a-keyword.

Lasse R.H. Nielsen

unread,
Jan 31, 2014, 8:43:14 AM1/31/14
to mi...@dartlang.org
You could probably modify your own copy of the dart2js compiler to accept dart:io and to have a patch file for dart:io. 
Dart2js uses the file sdk/lib/_internal/libraries.dart to see which libraries it should accept and where the patch files are. Changing the entry for "io" may (or may not) allow you to have dart2js compile files that uses dart:io.

Obviously, all warranties are void if you modify dart2js and it breaks :)

/L


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages