[erlang-questions] Announcing eipp: erlang bindings for c++
Daniel Goertzen
goertzen@REDACTED
Fri May 18 04:25:44 CEST 2007
Hi Dmitrii.
I'm not especially familiar with erl_interface, so I'll just talk a bit
about eipp so you get a feel for it.
The main class in eipp is "et" (erlang term). It is essentially a
variant type inspired by the "any" class from the boost library (earlier
revs were actually directly derived from boost::any). Any type that can
be transported by erlang etf can be represented by an et. Example:
et a,b,c;
a=123;
b=3.14;
c="i_am_an_atom";
eipp also provides runtime automatic casts for getting things out of et:
int x; double y; int z;
x=a;
y=b;
z=c; // throws bad_match exception, can't convert atom_t to int
eipp also has named constructors and destructurers for lists and tuples
(inspired by boost::tuple).
et a,b,x,y,z;
a=tuple(123,3.14,"an_atom");
b=list(1,2,3,"another_atom");
untuple(x,y,z)=a;
et supports the insert operator:
et a=tuple("example",3);
cout << a << endl;
output:
{example, 3}
eipp has a binary type, the primary use of which is for storing
serialized et instances. The binary type is really a pointer to
std::vector<char>, so you would need to drill into that type to get at
the raw data (ie, for transmitting through a socket for example).
sendN() functions are provided to send binaries to an iostream in a
format compatible with erlang port packet format.
et a=tuple("example",4)
et x=term_to_binary(a)
send4(cout,x);
Similarly, receiveN() functions are provided for receiving terms.
Internally, et instances decoded from a binary are different from
natively constructed et instances. Decoding is done "lazily", meaning
that the binary is kept around and the term is decoded just-in-time
(tuples and lists must be eagerly converted however, but not their
contents). The advantage to this is that unneeded terms don't have to
be decoded, and terms that are often not needed by a c++ program (funs,
pids) can be sent back to a real erlang node without ever being decoded.
All memory is automatically cleaned up (hooray for boost::shared_ptr !),
even for a bunch of decoded terms that may refer to the same binary.
eipp uses the encode & decode functions from ei, although I'd like to
work on producing native c++ transcoders. eipp does not do the erlang
distribution protocol, although that's something I'd like to add eventually.
Cheers,
Dan.
Dmitrii 'Mamut' Dimandt wrote:
> Daniel Goertzen wrote:
>
>> I'm please to announce "eipp": erlang bindings for c++. My employer
>> allowed me to open source this library, so many thanks to
>> http://www.norscan.com .
>>
>>
>>
> Hi!
>
> I've reposted your announcement to a russian site, http://rsdn.com
>
> I've been immediately asked the following:
>
> - How is it better than erl_interface?
> - There is no C++ in the example
> - Does cleans up terms automatically on free_term()?
>
> All this I resend to you as I've had just a tiny peek at the code and
> can't answer those questions for sure.
>
> Though my guess for eipp vs. erl_interface is that eipp is, at the very
> least, much less verbose.
>
>
> Go eipp :)
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
>
More information about the erlang-questions
mailing list