The functions PL_get_*()
read information from a Prolog
term. Most of them take two arguments. The first is the input term and
the second is a pointer to the output value or a term reference. The
return value is TRUE
or FALSE
, indicating the
success of the "get" operation. Most functions have a related "_ex"
function that raises an error if the argument is the operation cannot be
completed. If the Prolog term is not suitable, this is a type, domain or
instantiation error. If the receiving C type cannot represent the value
this is a representation error.
For integers an alternative interface exists, which helps deal with
the various integer types in C and C++. They are convenient for use with
_Generic
selection or C++ overloading.
BUF_STACK
implies, if the data is not static (as from an
atom), that the data is pushed on a stack. If BUF_MALLOC
is
used, the data must be freed using PL_free()
when no longer needed.
With the introduction of wide characters (see section
2.18.1), not all atoms can be converted into a char*
.
This function fails if t is of the wrong type, but also if
the text cannot be represented. See the REP_*
flags below
for details. See also PL_get_wchars()
and PL_get_nchars().
The first set of flags (CVT_ATOM
through CVT_VARIABLE
,
if set, are tested in order, using the first that matches. If none of
these match, then a check is made for one of CVT_WRITE
,
CVT_WRITE_CANONICAL
, CVT_WRITEQ
being set. If
none of the “CVT_WRITE*” flags are set, then a type_error
is raised.
CVT_RATIONAL
to represent rational numbers using
hexadecimal notation. Hexadecimal notation is notably useful for
transferring big integers to other programming environments if the
target system can read hexadecimal notation because the result is both
more compact and faster to write and read.CVT_RATIONAL
|
CVT_FLOAT
.
Note that
CVT_INTEGER
is implied by CVT_RATIONAL
.CVT_NUMBER
|
CVT_ATOM
|
CVT_STRING
.CVT_XINTEGER
is not
implied). Note that this does not include variables or terms (with the
exception of a list of characters/codes). Equivalent to
CVT_ATOMIC
|
CVT_LIST
._3290
).BUF_*
is provided, BUF_STACK
is implied.CVT_WRITE
, but using writeq/2.CVT_WRITE
, but using write_canonical/2.BUF_RING
is an alias
for BUF_STACK
. See section
12.4.14.PL_get_chars(l, s,
CVT_LIST|flags)
, provided flags
contains none of the CVT_*
flags.FALSE
.
If t is a floating point number that can be represented as a
long, this function succeeds as well. See also PL_get_int64()
and PL_get_long_ex().int64_t
, assign its value over i. See also PL_get_int64_ex().uint64_t
, assign its value over i. Note that
this requires GMP support for representing uint64_t
values
with the high bit set. See also PL_get_uint64_ex().true
, false
, set val
to the C constant TRUE
or FALSE
and return
success, otherwise return failure. The values on
, 1
, off
,
const0 and are also accepted.NULL
). This is the same as PL_get_name_arity(),
but this function fails if t is an atom.