Module value

Boxing and Unboxing Primitive Types.

All llib objects are by defiintion values; primitive types like ints (long long) , floats (double) and bools must be boxed first. Boxed types are pointers-to-primitive, which are not arrays; value_is_box becomes true. To box a value use value_int, value_float and value_bool; to check the type use the equivalent value_is_TYPE functions, and to extract the value use value_as_TYPE.

Error values are strings with a distinct type, so we have value_error and value_is_error.

value_parse converts strings to values using a known value type; value_tostring will convert a value to a default string representation. More complicated value types like arrays don’t have a unique representation as strings, so see json_tostring and xml_tostring.

See test-json.c for how values are used in practice.

Querying Type

value_is_box (v) is this a boxed value?
value_is_string (v) is this value a string?
value_is_error (v) is this value an error string?
value_is_float (v) does this value contain a double?
value_is_int (v) does this value contain a long long?
value_is_bool (v) does this value contain a bool?
value_is_simple_map (v) does this value represent a simple map?

Boxing Values

value_error (msg) make a error value.
value_float (x) box a double.
value_int (i) box a long long.
value_bool (i) box a bool.

Converting to and from Strings

value_parse (str, type) convert a string into a value of the desired type.
value_tostring (v) Default representation of a value as a string.


Querying Type

value_is_box (v)
is this a boxed value?

Parameters:

  • v PValue

Returns:

    bool
value_is_string (v)
is this value a string?

Parameters:

  • v PValue

Returns:

    bool
value_is_error (v)
is this value an error string?

Parameters:

  • v PValue

Returns:

    bool
value_is_float (v)
does this value contain a double?

Parameters:

  • v PValue

Returns:

    bool
value_is_int (v)
does this value contain a long long?

Parameters:

  • v PValue

Returns:

    bool
value_is_bool (v)
does this value contain a bool?

Parameters:

  • v PValue

Returns:

    bool
value_is_simple_map (v)
does this value represent a simple map?

Parameters:

  • v PValue

Returns:

    bool

Boxing Values

value_error (msg)
make a error value.

Parameters:

  • msg const char *

Returns:

    PValue
value_float (x)
box a double.

Parameters:

  • x double

Returns:

    PValue
value_int (i)
box a long long.

Parameters:

  • i long long

Returns:

    PValue
value_bool (i)
box a bool.

Parameters:

  • i bool

Returns:

    PValue

Converting to and from Strings

value_parse (str, type)
convert a string into a value of the desired type.

Parameters:

  • str const char *
  • type ValueType

Returns:

    PValue
value_tostring (v)
Default representation of a value as a string. Only applies to scalar values (if you want to show arrays & maps use json module).

Parameters:

  • v PValue

Returns:

    const char *
generated by LDoc 1.4.3 Last updated 2015-04-27 12:35:55