.. _vnx.Variant: vnx.Variant =========== .. cpp:namespace:: vnx::Variant `Variant` represents a value of arbitrary type which is assigned dynamically. It can be an integral (ie. ``int``, ``float``, ...), a ``string``, a ``vector`` of values, a ``set`` of values, a ``map`` of values or an :ref:`vnx.Object`, for example. JSON ---- In JSON format a `Variant` could be anything, for example: ``null``, ``true``, ``false``, a number, a string, an array of values or an object. Lua Script ---------- In Lua Script a `Variant` is a normal Lua variable and can be anyting, for example: ``nil``, ``true``, ``false``, a number, a string, an array of values, a table or an object. Native C++ ---------- In native C++ a `Variant` can be created / assigned as follows: .. code-block:: cpp #include vnx::Variant example(1234); std::cout << example.to() << std::endl; // 1234 example = "value"; std::cout << example.to() << std::endl; // value example = std::vector{1, 2, 3, 4}; std::cout << example << std::endl; // [1, 2, 3, 4] vnx::Object obj; obj["field"] = "value"; example = obj; std::cout << example << std::endl; // {"field": "value"}