Book Image

DART Essentials

Book Image

DART Essentials

Overview of this book

Table of Contents (16 chapters)
Dart Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The structure of native extensions


All native extensions in Dart are compiled as shared (also called dynamic) libraries and have to implement two main functions:

  • The <extension_name>_Init() function that is called by the Dart VM when the extension is loaded. Most importantly, it registers a handler that returns references to the extension's functions (typically called ResolveName()). We can use it to initialize some local variables, but most of the time, you'll use the default function from the example given by the Dart team. We'll use the default one here as well.

  • The ResolveName() function is called when we use the native keyword in Dart and is used to map functions from native extensions to Dart functions.

Typically, there's also a Dart class that wraps all calls to the native extension.

It's worth noting that there are conventions and caveats we have to follow. Otherwise, Dart won't be able to load our extension with quite an ambiguous error message: library handler failed. The premises...