[erlang-questions] best practice for calling C from Erlang
James Churchman
jameschurchman@REDACTED
Tue Dec 14 00:41:53 CET 2010
been wondering myself what the best way to interface D 2.0 is to erlang…. most of the usual C ones should would as you can call C (some C++) from D2.0
i am not sure what the best communication / serialisation mechanism is, but given a suitable one..
for auto generating if you don't already have a list of all function names then you could use ctags (available in macports etc… ) the "etags" (eg " etags my_c_file.c ") command will give you just the function names and return values, but no arity..
this might be ok as you could autoproduce a lookup table of function pointers in c, and assume the arity is given correct from the erlang code (eg from the length of an input array, tuple etc..) and call the function pointer with the arty of the supplied message from erlang just using a case for aritys upto say 10, otherwise ctags (eg " ctags my_c_file.c ") will give a much more verbose output and could be used to produce the exact code without function pointers, or even auto produce thrift / avro etc.. mappings .
i know that ctags this is used by text editors and plugins to allow the browsing of source.. so hopefully will give suitable quality output
On 13 Dec 2010, at 21:16, Jachym Holecek wrote:
> # Attila Rajmund Nohl 2010-12-13:
>> 2010/12/13, Timo Lindemann <timo.lindemann@REDACTED>:
>>> 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.
>>
>> Surely it's not much for one function. But for 125 functions it worth
>> considering generating code...
>
> BTW In complex cases, 'clang -fsyntax-only -Xclang -ast-print-xml -o a.xml a.c'
> comes in handy -- gives you straightforward XML description[*] of C APIs...
>
> Regards,
> -- Jachym
>
> [*] I mean straightforward after erlsom:simple_form/1 of course.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
More information about the erlang-questions
mailing list