dreamworkAPI
Ctrl K
GitHub
libraryDocs / vdf

vdf

librarysharedmenusource

The KeyValues format is used in the Source engine to store meta data for resources, scripts, materials, VGUI elements, and more..

Functions

vdf.deserializeConverts a KeyValues string into a key/value table (pure Lua implementation).
vdf.serializeConverts the given table into a KeyValues string (pure Lua implementation).

#vdf.deserialize

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
key_valuesstringThe KeyValues string to convert.
uses_escape_sequencesoptionalbooleanIf set to true, will replace \t, \n, \" and \\ with their escaped variants.
preserve_key_caseoptionalbooleanWhether to preserve key case or not (always lowercase).
Returns
TypeNameDescription
tableresultThe converted table.

#vdf.serialize

sharedmenunodiscardsource
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.

Parameters
NameTypeDescription
tbltableThe table to convert.
root_keyoptionalstringThe root key name, defaults to TableToKeyValues.
Returns
TypeNameDescription
stringkey_valuesThe KeyValues string.
Generated from the dreamwork meta branch.