組態資料物件 (cfg_data
)
此物件封裝用於產生組態檔案的組態值。更深入的描述可以在組態 Wiki 頁面中找到。
由以下項目回傳
組態資料物件由以下函式和方法回傳
組態資料物件方法
cfg_data.get()
回傳 varname
的值,如果該值尚未設定,則回傳 default_value
(如果已定義)(自 0.38.0 起),否則會產生錯誤
簽名
(自 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
)
引數
方法 cfg_data.get()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要查詢的變數名稱 |
|
default_value |
str | int | bool |
當 |
[選填] |
cfg_data.get_unquoted()
回傳 varname
的值,但不含周圍的雙引號 ("
)。如果該值尚未設定,則回傳 default_value
(如果已定義),否則會產生錯誤。
簽名
(自 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
)
引數
方法 cfg_data.get_unquoted()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要查詢的變數名稱 |
|
default_value |
str | int | bool |
當 |
[選填] |
cfg_data.has()
如果已設定指定的變數,則回傳 true
簽名
# returns `true` if the specified variable is set
bool has(
str varname, # The name of the variable to query
)
引數
方法 cfg_data.has()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要查詢的變數名稱 |
|
cfg_data.keys()
回傳組態資料物件的鍵陣列。
您可以使用 foreach
陳述式來迭代此陣列。
簽名
(自 0.57.0 起)
list[str] keys()
cfg_data.merge_from()
接受另一個組態資料物件作為引數,並將該物件的所有項目複製到目前物件。
簽名
(自 0.42.0 起)
# Takes as argument a different
void merge_from(
cfg_data other, # The other cfg_data
object to merge into this one.
)
引數
方法 cfg_data.merge_from()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
other |
cfg_data |
要合併到此物件的另一個 |
|
cfg_data.set()
將變數設定為給定的值
簽名
# 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
)
引數
方法 cfg_data.set()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要設定的變數名稱 |
|
value |
str | int | bool |
要設定的值 |
|
最後,cfg_data.set()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
description |
str |
將寫入結果檔案中的訊息/註解。此取代假設檔案具有 C 語法。如果您產生的檔案是其他語言的原始碼,您可能不想新增描述欄位,因為它很可能會導致語法錯誤。 |
|
cfg_data.set10()
與 cfg_data.set()
相同,但該值為 true
或 false
,將分別寫為 1 或 0
簽名
# 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
)
數值 < 0 的行為會令人驚訝地轉換為 true
,數值 > 1 的行為會更符合預期但無意地被解讀為 true
。
引數
方法 cfg_data.set10()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要設定的變數名稱 |
|
value |
bool | int |
要設定為 傳遞數字從來就不是預期的行為,且自 0.62 起已棄用。它將在 Meson 的未來版本中移除。如果您需要傳遞數字,請使用 |
|
最後,cfg_data.set10()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
description |
str |
將寫入結果檔案中的訊息/註解。此取代假設檔案具有 C 語法。如果您產生的檔案是其他語言的原始碼,您可能不想新增描述欄位,因為它很可能會導致語法錯誤。 |
|
cfg_data.set_quoted()
與 cfg_data.set()
相同,但會將值用雙引號 ("
) 括起來
簽名
# 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
)
引數
方法 cfg_data.set_quoted()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
要設定的變數名稱 |
|
value |
str | int | bool |
要設定的值 |
|
最後,cfg_data.set_quoted()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
description |
str |
將寫入結果檔案中的訊息/註解。此取代假設檔案具有 C 語法。如果您產生的檔案是其他語言的原始碼,您可能不想新增描述欄位,因為它很可能會導致語法錯誤。 |
|
搜尋結果為