vdf
The KeyValues format is used in the Source engine to store meta data for resources, scripts, materials, VGUI elements, and more..
Functions
vdf.deserialize | Converts a KeyValues string into a key/value table (pure Lua implementation). |
vdf.serialize | Converts the given table into a KeyValues string (pure Lua implementation). |
#vdf.deserialize
function vdf.deserialize(key_values: string, uses_escape_sequences?: boolean, preserve_key_case?: boolean): table
Converts a KeyValues string into a key/value table (pure Lua implementation).
The root key is discarded, its contents are returned.
Order is not preserved, repeated keys overwrite earlier ones, numeric keys and values are converted to numbers.
Supports quoted and unquoted tokens, // comments and skips [$CONDITION] blocks.
Raises a DecodeError (with the byte position of the problem) on unterminated strings or conditionals, keys without values, a missing root key or unbalanced braces, empty input decodes to an empty table.
| Name | Type | Description |
|---|---|---|
key_values | string | The KeyValues string to convert. |
uses_escape_sequencesoptional | boolean | If set to true, will replace \t, \n, \" and \\ with their escaped variants. |
preserve_key_caseoptional | boolean | Whether to preserve key case or not (always lowercase). |
| Type | Name | Description |
|---|---|---|
table | result | The converted table. |
#vdf.serialize
function vdf.serialize(tbl: table, root_key?: string): string
Converts the given table into a KeyValues string (pure Lua implementation).
Nested tables become sub-sections, booleans are written as 1/0, unsupported keys and values (functions, userdata, etc.) are skipped.
Raises an EncodeError on circular references.
\, ", \n and \t are escaped, so use uses_escape_sequences when deserializing.
| Name | Type | Description |
|---|---|---|
tbl | table | The table to convert. |
root_keyoptional | string | The root key name, defaults to TableToKeyValues. |
| Type | Name | Description |
|---|---|---|
string | key_values | The KeyValues string. |