[erlang-questions] Question on Erlang Port Driver
Iñaki Garay
igarai@REDACTED
Thu Jan 26 21:26:52 CET 2012
On Thu, Jan 26, 2012 at 07:00, Dave <ddd45cu@REDACTED> wrote:
> Quick beginner question in relation to the example given on the Erlang Port
> Drivers Interoperability Tutorial located at
> http://www.erlang.org/doc/tutorial/c_portdriver.html. How would this example
> (the complex5 module and the port_driver.c file) be expanded if you wanted
> to send/receive doubles instead of integers less than 256, while still
> sticking with the port_drivers interoperability and not switching to one of
> the other types? Such as if the c function you were creating ap ort to,
> complex.c, was:
>
>
>
> /* complex.c */
> double foo(double x) {
> return x/1.0;
> }
> double bar(double y) {
> return y/2.0;
> }
The ei library is your friend:
http://www.erlang.org/doc/man/ei.html#ei_decode_double
I don't think using ei on the C side will hurt interoperability,
others may correct me.
Also read:
http://www.erlang.org/doc/apps/erl_interface/users_guide.html
http://www.erlang.org/doc/tutorial/erl_interface.html
Common pitfalls when working with ei are forgetting to send the
version info, and errors handling memory for the buffer.
The _x_ versions of the ei functions which use dynamic buffers are recommended.
good luck!
Iñaki Garay
More information about the erlang-questions
mailing list