[erlang-questions] Wrapping C libraries in pure Erlang

Denis Bilenko denis.bilenko@REDACTED
Wed Apr 4 20:30:50 CEST 2007


Mats Cronqvist wrote:

>    i think the "proper" way to wrap external libraries (esp native GUI) is to
> create a c-node (i.e. a server process that implements the erlang distribution
> protocol). the call to time() is wrapped in (say) Time(), accessible thus;
>
>    libc ! {'Time',[]},
>    receive
>      {libc,{ok,Ans}} -> Ans
>    end
>
>    many/most wrappers can be auto generated from the C header files.
>
>    this is verifiably possible (and even easy), since I've done exactly this
> with GTK (http://code.google.com/p/gtknode).
>
>    a c-node is safe and easy to work with. in my experience, linked in drivers
> are more trouble than their worth.

That's why I want an ultimate linked-in driver -- to abstract them out, and
never have to work with them again (except, maybe, for performance reasons).

c-node is safe to work with, but erlang-node is just as safe. and it must be
easier to work with -- after all, it is a high-level dynamic Erlang versus C.
A bridge between dynamic language interpreter and C can be build from either
end. ctypes has demonstrated that building Python wrappers to C libraries
in Python itself is a good thing (or at least a very easy thing:).
I think that would be true for Erlang too.

Thank you for the pointer.
C-node around libffi can be useful, but it is limited compared
to driver (but I can always turn driver into a separate node).
What if I want to make just one system call?
It doesn't seem natural to start a node for it.
What if this call receives file descriptor?
Now it doesn't even seem possible.

Denis.



More information about the erlang-questions mailing list