![]() |
![]()
| ![]() |
![]()
NAMEerl_eterm - Functions for Erlang term construction.DESCRIPTIONThis module provides 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, as it can be changed in future releases to provide faster and more compact term storage. Instead, applications should use the macros and functions provided. Each of the following macros takes a single ETERM pointer as an argument. The macros return a non-zero value if the test is true, otherwise 0.
EXPORTSETERM *erl_cons(head, tail)
Types:
ETERM *head;
Concatenates two Erlang terms, prepending head onto tail and
thereby creating a cons cell. To make a proper list, tail is
always to be a list or an empty list. Notice that NULL is not a valid
list.
ETERM *erl_copy_term(term)
ETERM *list,*anAtom,*anInt; anAtom = erl_mk_atom("madonna"); anInt = erl_mk_int(21); list = erl_mk_empty_list(); list = erl_cons(anAtom, list); list = erl_cons(anInt, list); ... /* do some work */ erl_free_compound(list);
Types:
ETERM *term;
Creates and returns a copy of the Erlang term term.
ETERM *erl_element(position, tuple)
Types:
int position;
Extracts a specified element from an Erlang tuple.
ETERM *erl_hd(list)
Types:
ETERM *list;
Extracts the first element from a list.
list is an Erlang term containing a list.
Returns an Erlang term corresponding to the head head element in the list, or a
NULL pointer if list was not a list.
void erl_init(NULL, 0)
Types:
void *NULL;
This function must be called before any of the others in the
Erl_Interface library to initialize the library functions. The
arguments must be specified as erl_init(NULL,0).
int erl_iolist_length(list)
Types:
ETERM *list;
Returns the length of an I/O list.
list is an Erlang term containing an I/O list.
Returns the length of list, or -1 if list is not an I/O
list.
For the definition of an I/O list, see erl_iolist_to_binary.
ETERM *erl_iolist_to_binary(term)
Types:
ETERM *list;
Converts an I/O list to a binary term.
list is an Erlang term containing a list.
Returns an Erlang binary term, or NULL if list was not an I/O
list.
Informally, an I/O list is a deep list of characters and binaries that can be
sent to an Erlang port. In BNF, an I/O list is formally defined as follows:
char *erl_iolist_to_string(list)
iolist ::= [] | Binary | [iohead | iolist] ; iohead ::= Binary | Byte (integer in the range [0..255]) | iolist ;
Types:
ETERM *list;
Converts an I/O list to a NULL-terminated C string.
list is an Erlang term containing an I/O list. The I/O list must not
contain the integer 0, as C strings may not contain this value except as a
terminating marker.
Returns a pointer to a dynamically allocated buffer containing a string. If
list is not an I/O list, or if list contains the integer 0,
NULL is returned. It is the caller's responsibility to free the
allocated buffer with erl_free().
For the definition of an I/O list, see erl_iolist_to_binary.
int erl_length(list)
Types:
ETERM *list;
Determines the length of a proper list.
list is an Erlang term containing a proper list. In a proper list, all
tails except the last point to another list cell, and the last tail points to
an empty list.
Returns -1 if list is not a proper list.
ETERM *erl_mk_atom(string)
Types:
const char *string;
Creates an atom.
string is the sequence of characters that will be used to create the
atom.
Returns an Erlang term containing an atom. Notice that it is the caller's
responsibility to ensure 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) return the
length of the atom name.
ETERM *erl_mk_binary(bptr, size)
Note:
The UTF-8 variants were introduced in Erlang/OTP R16 and the string returned by
ERL_ATOM_PTR(atom) was not NULL-terminated on older releases.
Types:
char *bptr;
Produces an Erlang binary object from a buffer containing a sequence of bytes.
ETERM *erl_mk_empty_list()
Creates and returns an empty Erlang list. Notice that NULL is not used to
represent an empty list; Use this function instead.
ETERM *erl_mk_estring(string, len)
Types:
char *string;
Creates a list from a sequence of bytes.
ETERM *erl_mk_float(f)
Types:
double f;
Creates an Erlang float.
f is a value to be converted to an Erlang float.
Returns an Erlang float object with the value specified in f or
NULL if f is not finite.
ERL_FLOAT_VALUE(t) can be used to retrieve the value from an Erlang
float.
ETERM *erl_mk_int(n)
Types:
int n;
Creates an Erlang integer.
n is a value to be converted to an Erlang integer.
Returns an Erlang integer object with the value specified in n.
ERL_INT_VALUE(t) can be used to retrieve the value from an Erlang
integer.
ETERM *erl_mk_list(array, arrsize)
Types:
ETERM **array;
Creates an Erlang list from an array of Erlang terms, such that each element in
the list corresponds to one element in the array.
ETERM *erl_mk_long_ref(node, n1, n2, n3, creation)
Types:
const char *node;
Creates an Erlang reference, with 82 bits.
ETERM *erl_mk_pid(node, number, serial, creation)
Types:
const char *node;
Creates an Erlang process identifier (pid). The resulting pid can be used by
Erlang processes wishing to communicate with the C-node.
ETERM *erl_mk_port(node, number, creation)
Types:
const char *node;
Creates an Erlang port identifier.
ETERM *erl_mk_ref(node, number, creation)
Types:
const char *node;
Creates an old Erlang reference, with only 18 bits - use erl_mk_long_ref
instead.
ETERM *erl_mk_string(string)
Types:
char *string;
Creates a list from a NULL-terminated string.
string is a NULL-terminated sequence of characters (that is, a C
string) from which the list will be created.
Returns an Erlang list.
ETERM *erl_mk_tuple(array, arrsize)
Types:
ETERM **array;
Creates an Erlang tuple from an array of Erlang terms.
ETERM *erl_mk_uint(n)
Types:
unsigned int n;
Creates an Erlang unsigned integer.
n is a value to be converted to an Erlang unsigned integer.
Returns an Erlang unsigned integer object with the value specified in n.
ERL_INT_UVALUE(t) can be used to retrieve the value from an Erlang
unsigned integer.
ETERM *erl_mk_var(name)
Types:
char *name;
Creates an unbound Erlang variable. The variable can later be bound through
pattern matching or assignment.
name specifies a name for the variable.
Returns an Erlang variable object with the name name.
int erl_print_term(stream, term)
Types:
FILE *stream;
Prints the specified Erlang term to the specified output stream.
void erl_set_compat_rel(release_number)
Types:
unsigned release_number;
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
Erlang/OTP R10 is not compatible with an Erlang emulator from Erlang/OTP R9 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.
int erl_size(term)
Note:
If this function is called, it may only be called once directly after the call
to function erl_init().
Warning:
You may run into trouble if this feature is used carelessly. Always ensure 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.
Types:
ETERM *term;
Returns either the arity of an Erlang tuple or the number of bytes in an Erlang
binary object.
term is an Erlang tuple or an Erlang binary object.
Returns the size of term as described above, or -1 if term
is not one of the two supported types.
ETERM *erl_tl(list)
Types:
ETERM *list;
Extracts the tail from a list.
list is an Erlang term containing a list.
Returns an Erlang list corresponding to the original list minus the first
element, or NULL pointer if list was not a list.
ETERM *erl_var_content(term, name)
Types:
ETERM *term;
Returns the contents of the specified variable in an Erlang term.
|