yaml.encode(value)function
Encodes the given Lua table into a YAML string.
This function supports sequences (table with integer keys), mappings (tables with string keys), multiple documents (when given an array of tables), and preserves types following this rules :
| Lua value type | YAML |
|---|---|
"string" |
"string" |
number |
number |
boolean |
boolean |
table (non array) |
YAML mapping {} |
table (integer keys) |
YAML sequence [] |
|
null |
object |
Not supported (raises an error) |
thread |
Not supported (raises an error) |
userdata |
Not supported (raises an error) |
Parameters
value
The Lua table to encode to YAML string.
Return value
Returns the YAML representation as astring.
Example
--! luart-extensions
import yaml
local t = {name = "Alice", age = 30}
local ystr = yaml.encode(t)
print(ystr)