[erlang-questions] Wrapping C libraries in pure Erlang

Mats Cronqvist mats.cronqvist@REDACTED
Wed Apr 4 16:05:41 CEST 2007


Denis Bilenko wrote:

[...]
> One useful application would be accessing system calls not
> covered by existing BIFs/drivers (native GUI goes in this
> category)
> 
> I would like to hear any comments, especially from people who
> know something about Erlang internals (I don't):
> Would it be hard to implement?
> Has anyone already thought of something like that?

   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.

   mats



More information about the erlang-questions mailing list