GLib.Variant.new

function new(type: String, value: Any): GLib.Variant {
    // Gjs wrapper for g_variant_new_array()
}
  

Creates a new GLib.Variant according to the type provided, which must be a definite type.

If type is a fundamental numeric or string type, then value must be an appropriate JS primitive value.

If type is v, then value must be a GLib.Variant.

If type ia a maybe type, then value can be null or a value of the correct type.

If type is an array type, then value must be an array of appropriate values. As a special case, if type is ay, then a ByteArray can be used, which can avoid memory copies when not needed.

If type is a tuple, then value must be an array of appropriate values, whose length must be the number of elements in the tuple.

If type is a dictionary entry, then value must be a two elements array, where the two elements are the key and the value. As a special case, to obtain an array of dictionary entries (ie, a dictionary) you must not pass an array of two-element arrays but an object whose property names are the dictionary keys and whose property values are the dictionary values.

let int = new GLib.Variant('u', 42);
let tuple = new GLib.Variant('(us)', [42, 'foo']);
let array = new GLib.Variant('as', ['foo', 'bar', 'baz']);
let byteArray = new GLib.Variant('ay', 'byte content');
let dictionary = new GLib.Variant('a{sv}', { 'key1': new GLib.Variant('u', 42),
                                             'key2': new GLib.Variant('s', 'string') });
  
type

the type of the new variant, as a string

value

the JS value to build the GLib.Variant from

Returns

a new GLib.Variant