中文 | English
API: wingman.config
Configuration management module, used to read and write the application configuration.
Module Overview
The config module provides configuration read/write functionality, supporting:
- Custom configuration - store user-defined key-value pairs
- Persistence - save the configuration to disk and load it from disk
Get a Custom Config Entry
get(key) / get(key)
Description: Gets a custom configuration value.
Function signature:
python
get(key: str) -> Anylua
get(key: string) -> anyParameters:
key- the config entry key name. Keys are top-level strings; dot-path nesting is not supported (passinggame.characterlooks up a top-level key literally named that string)
Returns:
- The configuration value (a string), or
None/nilwhen it does not exist
python
from wingman import config
value = config.get("myKey")
if value:
print(value)Set a Custom Config Entry
set(key, value) / set(key, value)
Description: Sets a custom configuration value.
Function signature:
python
set(key: str, value: str) -> Nonelua
set(key: string, value: string) -> nilParameters:
key- the config entry key name. Keys are top-level strings; dot-path nesting is not supportedvalue- the configuration value, strings only. Non-string values (numbers, booleans, tables, etc.) are silently stored as an empty string; for non-string JSON types, pass a JSON string (ajson::parseis performed internally, e.g.config.set("count", "42")stores the number 42)
python
from wingman import config
# 简单键值(值必须为字符串)
config.set("myKey", "myValue")
config.set("count", "42") # 存为 JSON 数字 42
config.set("enabled", "true") # 存为 JSON 布尔 trueDelete a Custom Config Entry
remove(key) / remove(key)
Description: Deletes a custom configuration value.
Function signature:
python
remove(key: str) -> boollua
remove(key: string) -> booleanParameters:
key- the config entry key name
Returns:
- Whether the deletion succeeded (returns
True/trueif the key exists, otherwiseFalse/false)
python
from wingman import config
removed = config.remove("myKey")
if removed:
print("配置已删除")
else:
print("配置不存在")Save the Configuration
save() / save()
Description: Saves the current configuration to disk.
Function signature:
python
save() -> boollua
save() -> booleanReturns:
- bool: whether saving succeeded (the current implementation writes JSON directly, so it is always
True/true)
python
from wingman import config
# 修改后保存到磁盘
config.set("myKey", "myValue")
config.save()Load the Configuration
load() / load()
Description: Loads the configuration from disk.
Function signature:
python
load() -> boollua
load() -> booleanReturns:
- bool: whether loading succeeded (the current implementation reads JSON directly, so it is always
True/true)
python
from wingman import config
# 从磁盘重新加载配置
config.load()Available Interfaces
| Python function | Lua function | Description | Parameters |
|---|---|---|---|
get(key) | get(key) | Get custom configuration | key: key name (top-level string, no nested paths) Return: string, None/nil if not present |
set(key, value) | set(key, value) | Set custom configuration | key: key name, value: strings only (non-strings are silently stored as an empty string; pass JSON strings for JSON types) |
remove(key) | remove(key) | Delete custom configuration | key: key name |
save() | save() | Save the configuration to disk | None |
load() | load() | Load the configuration from disk | None |