tree: 3bb92d3076bda5eb1d5228980e474b0844f64451
  1. bin/
  2. data/
  3. hook/
  4. lib/
  5. test/
  6. third_party/
  7. tool/
  8. .gitignore
  9. pubspec.yaml
  10. README.md
pkgs/code_assets/example/stb_image/README.md

stb_image

This project is a minimal, cross-platform demonstration of how to use Dart‘s build hooks, with code assets and dart:ffi to call a simple function from a popular C library. This project uses stbi_info from the stb_image.h library to read an image’s dimensions and color channels without loading the entire file into memory.

How it works

The native code is built by the hook/build.dart, which is run by the Dart SDK CLI tools. This build hook compiles the C code from third_party/stb_image.c into a dynamic library.

The Dart FFI bindings to the C code are generated by tool/ffigen.dart. FFIgen generates Dart FFI bindings from third_party/stb_image.h into lib/src/third_party/stb_image.g.dart.

The Dart code in lib/stb_image.dart uses the generated FFI bindings to provide a Dart API (not exposing any C types).