erl_eterm

C LIBRARY

erl_eterm

LIBRARY SUMMARY

Functions for Erlang Term Construction

DESCRIPTION

This module contains functions for creating and manipulating
Erlang terms.

An Erlang term is represented by a C structure of type
ETERM. Applications should not reference any fields in this
structure directly, because it may be changed in future releases
to provide faster and more compact term storage. Instead,
applications should us the macros and functions provided.

The following macros each take a single ETERM pointer as an
argument. They return a non-zero value if the test is true, and 0
otherwise:

ERL_IS_INTEGER(t)

True if t is an integer.

ERL_IS_UNSIGNED_INTEGER(t)

True if t is an integer.

ERL_IS_FLOAT(t)

True if t is a floating point number.

ERL_IS_ATOM(t)

True if t is an atom.

ERL_IS_PID(t)

True if t is a Pid (process identifier).

ERL_IS_PORT(t)

True if t is a port.

ERL_IS_REF(t)

True if t is a reference.

ERL_IS_TUPLE(t)

True if t is a tuple.

ERL_IS_BINARY(t)

True if t is a binary.

ERL_IS_LIST(t)

True if t is a list with zero or more elements.

ERL_IS_EMPTY_LIST(t)

True if t is an empty list.

ERL_IS_CONS(t)

True if t is a list with at least one element.

The following macros can be used for retrieving parts of Erlang
terms. None of these do any type checking; results are undefined
if you pass an ETERM* containing the wrong type. For example,
passing a tuple to ERL_ATOM_PTR() will likely result in garbage.

char *ERL_ATOM_PTR(t)

char *ERL_ATOM_PTR_UTF8(t)

A string representing atom t.

int ERL_ATOM_SIZE(t)

int ERL_ATOM_SIZE_UTF8(t)

The length (in bytes) of atom t.

void *ERL_BIN_PTR(t)

A pointer to the contents of t

int ERL_BIN_SIZE(t)

The length (in bytes) of binary object t.

int ERL_INT_VALUE(t)

The integer of t.

unsigned int ERL_INT_UVALUE(t)

The unsigned integer value of t.

double ERL_FLOAT_VALUE(t)

The floating point value of t.

ETERM *ERL_PID_NODE(t)

ETERM *ERL_PID_NODE_UTF8(t)

The Node in pid t.

int ERL_PID_NUMBER(t)

The sequence number in pid t.

int ERL_PID_SERIAL(t)

The serial number in pid t.

int ERL_PID_CREATION(t)

The creation number in pid t.

int ERL_PORT_NUMBER(t)

The sequence number in port t.

int ERL_PORT_CREATION(t)

The creation number in port t.

ETERM *ERL_PORT_NODE(t)

ETERM *ERL_PORT_NODE_UTF8(t)

The node in port t.

int ERL_REF_NUMBER(t)

The first part of the reference number in ref t. Use
only for compatibility.

int ERL_REF_NUMBERS(t)

Pointer to the array of reference numbers in ref t.

int ERL_REF_LEN(t)

The number of used reference numbers in ref t.

int ERL_REF_CREATION(t)

The creation number in ref t.

int ERL_TUPLE_SIZE(t)

The number of elements in tuple t.

ETERM *ERL_CONS_HEAD(t)

The head element of list t.

ETERM *ERL_CONS_TAIL(t)

A List representing the tail elements of list t.

EXPORTS

This function concatenates two Erlang terms, prepending
head onto tail and thereby creating a cons cell.
To make a proper list, tail should always be a
list or an empty list. Note that NULL is not a valid list.

head is the new term to be added.

tail is the existing list to which head will
be concatenated.

The function returns a new list.

ERL_CONS_HEAD(list) and ERL_CONS_TAIL(list)
can be used to retrieve the head and tail components
from the list. erl_hd(list) and erl_tl(list) will do
the same thing, but check that the argument really is a list.

list is an Erlang term containing an IO list. The IO
list must not contain the integer 0, since C strings may not
contain this value except as a terminating marker.

This function returns a pointer to a dynamically allocated
buffer containing a string. If list is not an IO list,
or if list contains the integer 0, NULL is returned. It
is the caller's responsibility free the allocated buffer
with erl_free().

string is the sequence of characters that will be
used to create the atom.

Returns an Erlang term containing an atom. Note that it is
the callers responsibility to make sure that string
contains a valid name for an atom.

ERL_ATOM_PTR(atom) and ERL_ATOM_PTR_UTF8(atom)
can be used to retrieve the atom name (as a null terminated string). ERL_ATOM_SIZE(atom)
and ERL_ATOM_SIZE_UTF8(atom) returns the length of the atom name.

Note

Note that the UTF8 variants were introduced in Erlang/OTP releases R16
and the string returned by ERL_ATOM_PTR(atom) was not null terminated on older releases.

The function creates an Erlang tuple, whose arity is
size and whose elements are taken from the terms in
array.

To retrieve the size of a tuple, either use the
erl_size function (which checks the type of the checked
term and works for a binary as well as for a tuple), or the
ERL_TUPLE_SIZE(tuple) returns the arity of a tuple.
erl_size() will do the same thing, but it checks that
the argument really is a tuple.
erl_element(index,tuple) returns the element
corresponding to a given position in the tuple.

By default, the erl_interface library is only guaranteed
to be compatible with other Erlang/OTP components from the same
release as the erl_interface library itself. For example,
erl_interface from the OTP R10 release is not compatible
with an Erlang emulator from the OTP R9 release by default.

A call to erl_set_compat_rel(release_number) sets the
erl_interface library in compatibility mode of release
release_number. Valid range of release_number
is [7, current release]. This makes it possible to
communicate with Erlang/OTP components from earlier releases.

Note

If this function is called, it may only be called once
directly after the call to the
erl_init() function.

Warning

You may run into trouble if this feature is used
carelessly. Always make sure that all communicating
components are either from the same Erlang/OTP release, or
from release X and release Y where all components
from release Y are in compatibility mode of release X.

This function returns the contents of the specified
variable in an Erlang term.

term is an Erlang term. In order for this function
to succeed, term must be an Erlang variable with the
specified name, or it must be an Erlang list or tuple
containing a variable with the specified name. Other Erlang
types cannot contain variables.

name is the name of an Erlang variable.

Returns the Erlang object corresponding to the value of
name in term. If no variable with the name
name was found in term, or if term is
not a valid Erlang term, NULL is returned.