[erlang-questions] best practice for calling C from Erlang

Timo Lindemann timo.lindemann@REDACTED
Mon Dec 13 15:46:35 CET 2010


Hi,

I have made good experiences with the new NIF interface, having hacked an
interface to libtidy in one afternoon, and I didn't even know what NIFs were
until that morning, so I can definitely say that this is a very easy
interface for crossing the boundary quickly. Automatic generation of an
interface I don't know much about, I just wanted to chime in to say that
NIFs are easy to do, and the wrapper is so thin you might not need to
autogenerate it, there's very little boilerplate left to autogenerate. Of
course if a NIF gets a SEGV it all crashes (learned that first thing :-) ).

It's really straightforward to do if you need it to work quickly. Mine got
the job done, but wasn't the best possible implementation, but it was sort
of an one-shot thing.

Best regards
-T.

2010/12/13 Joe Armstrong <erlang@REDACTED>

> What is "best practice for calling C from Erlang"
>
> I have a C library I want to call from Erlang - nothing complicated.
> Mostly the C functions are called with simple types, integers, strings etc.
> and the return value is uninteresting. In the case where the return value
> is
> interesting I mostly require an opaque return value - ie all I might
> ever want to do
> is re-use it in a subsequent call to a different C routine, so the actual
> return
> value need never cross the C/Erlang boundary, but could be passed back
> and forth
> as a reference.
>
> What is the best (and easiest) way to call this from Erlang.
> Is there any program that takes a file containing C type declarations
> (either in ANSI C, or as a erlang terms) and automatically builds
> the C and Erlang sides of the interface?
>
> The problem here is not the complexity of an individual
> call, but the fact there are a large number of simple and rather
> boring functions than must be called.
>
> I know all about the ports
> interface linked-in drivers etc. My question is more to do with
> the automatic generation of an interface from some kind of specification.
>
> /Joe
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


-- 
Timo Lindemann
Software Systems Engineer
+49 (0) 160 99 13 06 23
Mon-Thu 0900 - 1700 (GMT +1)

SOL VENETUS Software GmbH
Seb.-Kneipp-Str. 2, 86482 Aystetten
Telefon: +49 (0) 170 77 62 48 0
Telefax: +49 (0) 821 48 65 78 6
Geschäftsführer: Benjamin Hilbig
Amtsgericht Augsburg, HRB 24559
USt.-IdNr.: DE267014985


More information about the erlang-questions mailing list