Configuration data object (cfg_data)

This object encapsulates configuration values to be used for generating configuration files. A more in-depth description can be found in the the configuration wiki page.

Returned by

Configuration data object objects are returned by the following functions and methods:

Configuration data object methods

cfg_data.get()

Returns the value of varname, if the value has not been set returns default_value if it is defined (since 0.38.0) and errors out if not

Signature

(since 0.38.0)

# Returns the value of `varname`, if the
str | int | bool get(
  str              varname,           # The name of the variable to query
  str | int | bool [default_value],   # The default value to return when `varname` does not exist
)

Arguments

The method cfg_data.get() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to query

default_value str | int | bool

The default value to return when varname does not exist

[optional]


cfg_data.get_unquoted()

Returns the value of varname but without surrounding double quotes ("). If the value has not been set returns default_value if it is defined and errors out if not.

Signature

(since 0.44.0)

# Returns the value
str | int | bool get_unquoted(
  str              varname,           # The name of the variable to query
  str | int | bool [default_value],   # The default value to return when `varname` does not exist
)

Arguments

The method cfg_data.get_unquoted() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to query

default_value str | int | bool

The default value to return when varname does not exist

[optional]


cfg_data.has()

returns true if the specified variable is set

Signature

# returns `true` if the specified variable is set
bool has(
  str varname,     # The name of the variable to query
)

Arguments

The method cfg_data.has() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to query


cfg_data.keys()

Returns an array of keys of the configuration data object.

You can iterate over this array with the foreach statement.

Signature

(since 0.57.0)

list[str] keys()


cfg_data.merge_from()

Takes as argument a different configuration data object and copies all entries from that object to the current.

Signature

(since 0.42.0)

# Takes as argument a different
void merge_from(
  cfg_data other,     # The other cfg_data object to merge into this one.
)

Arguments

The method cfg_data.merge_from() accepts the following positional arguments:

Name Type Description Tags
other cfg_data

The other cfg_data object to merge into this one.


cfg_data.set()

Sets a variable to a given value

Signature

# Sets a variable to a given value
void set(
  str              varname,     # The name of the variable to set
  str | int | bool value,       # The value to set

  # Keyword arguments:
  description : str  # Message / Comment that will be written in the
)

Arguments

The method cfg_data.set() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to set

value str | int | bool

The value to set

Finally, cfg_data.set() accepts the following keyword arguments:

Name Type Description Tags
description str

Message / Comment that will be written in the result file. The replacement assumes a file with C syntax. If your generated file is source code in some other language, you probably don't want to add a description field because it most likely will cause a syntax error.


cfg_data.set10()

Is the same as cfg_data.set() but the value is either true or false and will be written as 1 or 0, respectively

Signature

# Is the same as cfg_data.set() but the value
void set10(
  str        varname,     # The name of the variable to set
  bool | int value,       # The value to set as either `1` or `0`

  # Keyword arguments:
  description : str  # Message / Comment that will be written in the
)
Warning:

numeric values < 0 have the surprising behavior of being converted to true, values > 1 have the more expected but unintentional behavior of being interpreted as true.

Arguments

The method cfg_data.set10() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to set

value bool | int

The value to set as either 1 or 0

Passing numbers was never intended to work, and since 0.62 it has been deprecated. It will be removed in a future version of Meson. If you need to pass numbers use the .set method.

Finally, cfg_data.set10() accepts the following keyword arguments:

Name Type Description Tags
description str

Message / Comment that will be written in the result file. The replacement assumes a file with C syntax. If your generated file is source code in some other language, you probably don't want to add a description field because it most likely will cause a syntax error.


cfg_data.set_quoted()

Is same as cfg_data.set() but quotes the value in double quotes (")

Signature

# Is same as cfg_data.set() but quotes the value in double quotes (`"`)
void set_quoted(
  str              varname,     # The name of the variable to set
  str | int | bool value,       # The value to set

  # Keyword arguments:
  description : str  # Message / Comment that will be written in the
)

Arguments

The method cfg_data.set_quoted() accepts the following positional arguments:

Name Type Description Tags
varname str

The name of the variable to set

value str | int | bool

The value to set

Finally, cfg_data.set_quoted() accepts the following keyword arguments:

Name Type Description Tags
description str

Message / Comment that will be written in the result file. The replacement assumes a file with C syntax. If your generated file is source code in some other language, you probably don't want to add a description field because it most likely will cause a syntax error.


The results of the search are