Giter VIP home page Giter VIP logo

racket-autoffi's Introduction

Racket AutoFFI

This is the Racket binding generator built on top of AutoFFI.

Installation

raco pkg install https://github.com/AutoFFI/racket-autoffi.git

Getting Started

This is a very basic example showing what AutoFFI is capable of doing.

Say we have the following program in plain C:

myprog.c

int add(int a, int b) {
  return a + b;
}

We can compile this program on OS X as follows:

$ clang -o myprog.dylib -shared myprog.c

This gives us a binary:

$ hexdump myprog.dylib
0000000 cf fa ed fe 07 00 00 01 03 00 00 00 06 00 00 00
0000010 0c 00 00 00 78 02 00 00 85 00 10 00 00 00 00 00
0000020 19 00 00 00 e8 00 00 00 5f 5f 54 45 58 54 00 00
0000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0000040 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...

The binary does not contain enough information to link to it. AutoFFI generates the missing type information. In order to do this, we need our AutoFFI tool:

$ affc myprog.c > myprog.json

Importing this binary in Racket now requires only two lines of code. No need to define complex FFI structures!

main.rkt

#lang racket
(require autoffi)
(require/foreign "myprog")
(add 1 2)

If we run this program, we get:

$ racket test.rkt
3

That's it! Programs can get much more complicated, of course. Any bugs should be posted in the issue tracker.

racket-autoffi's People

Watchers

James Cloos avatar

Forkers

happy-ferret

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.