Giter VIP home page Giter VIP logo

nifty's Introduction

Travis Erlang Versions Clang Versions Last Commit

Nifty - Erlang NIF Wrapper Generator

Nifty is an interface generator that allows the use of C modules from Erlang.

Web page: [http://parapluu.github.io/nifty/]

A Simple Example

Let's say we have two C files mylib.h and mylib.c which we want to use in our Erlang application:

/* mylib.h */
extern int fib(int n);
/* mylib.c */
int
fib(int n) {
  if (n <= 2) {
    return 1;
  } else {
    return fib(n-1) + fib(n-2);
  }
}

We can generate a NIF interface and use it from Erlang with the following command:

nifty:compile("mylib.h", mylib, nifty_utils:add_sources(["mylib.c"], [])).
5 = mylib:fib(5).

nifty:compile/3 gets as its first argument a header or interface file and tries to generate an interface for all specified functions. The second argument specifies the Erlang module the interface is about to use and the third argument is used for additional options. These options are compatible with the ones rebar uses to compile NIF modules. In fact, Nifty uses rebar to compile the generated interface.

Installation

After successfully cloning enter the following commands

make

and include Nifty in your ERL_LIBS path.

Unit Tests

Run the following command to check that everything works correct:

make tests

Dependencies

  • The clang compiler and libclang, including the header files.
  • [Optional] PropEr for the unit tests.

Base Types

C Types Erlang Types Nifty Type Name
signed int or int integer() nifty.int
unsigned int integer() nifty.unsigned int
char integer() nifty.char
short integer() nifty.short
long integer() nifty.long
long long integer() nifty.long long
float float() nifty.float
double float() nifty.double
<type> * {integer(), string()} <module>.<type> *

Known Limitations

  • Function pointers are only partially supported.
  • There is no support for anonymous structs and unions.
  • Functions using unsupported types are not translated and a warning is issued.
  • Functions with a variable number of arguments (va_list or ...) are not supported. If va_list as type is used, Nifty will print a warning. If ... is used, then the function is translated without the variable arguments: int printf(const char *format, ...) will be translated into printf/1.
  • The usage of incomplete types is limited.
  • Nifty has not been tested under Windows.

nifty's People

Contributors

kostis avatar thegeorge avatar terry-xiaoyu avatar sg2342 avatar

Watchers

James Cloos avatar

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.