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<T> of values, a set<T> of values, a map<K, V> of values or an 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:

#include <vnx/vnx.h>

vnx::Variant example(1234);

std::cout << example.to<int>() << std::endl;    // 1234

example = "value";

std::cout << example.to<std::string>() << std::endl;    // value

example = std::vector<int>{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"}