GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — FFI

FFI

Jump to bottom
Andy Arvanitis edited this page Jul 26, 2019 · 3 revisions

C++11 target foreign exports

  • Foreign values are resolved dynamically/lazily (and "cached" thereafter), so you don't need to define all of them right away. If needed and missing during runtime, an exception will be thrown. Using a source-level debugger which supports C++ will reveal the missing implementation easily enough.

  • To implement foreign values to be exported:

    1. Create a C++ source file (typically in your_workspace/ffi)
    2. #include purescript.h and any other C/C++ dependencies
    3. Use macros FOREIGN_BEGIN( Module_Name ) and FOREIGN_END to delineate your block of exported values.
      For example:
      #include "purescript.h"
      
      // Tested with package v4.0.0
      
      FOREIGN_BEGIN( Data_Semigroup )
      
      exports["concatString"] = [](const boxed& s1) -> boxed {
          return [=](const boxed& s2) -> boxed {
              return unbox<string>(s1) + unbox<string>(s2);
          };
      };
      
      FOREIGN_END
  • See the standard library implementations for more examples

Clone this wiki locally

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.