﻿LuaHUML
HUML decoder and encoder
Version 0.1.2
For Lua Versions 5.1 to 5.5
For HUML Version 0.2.0

This is a module that converts data from HUML to Lua and vice versa. Information about HUML can be found at huml.io.

Exported Functions

decode(huml_string)
-- Returns a Lua value, or nil along with an error message if failed.

encode(lua_value, [escape_control_characters, [split_numbers]])
-- Returns a HUML string, or nil along with an error message if failed.
-- If escape_control_characters is truthy, canonical control characters will be converted into their escaped representations. Multiline strings will be precluded since the newlines will become «\n».
-- If split_numbers is truthy, decimals like 5000000 will be represented as «5_000_000», as supported by the HUML spec.

Notes

When encoding, since HUML has a distinction between lists and dicts while Lua does not, Lua tables that contain only numerical keys will be converted into HUML lists, and all other Lua tables will be converted into HUML dicts, in which case, all keys will be converted into strings. Duplicate keys are not allowed in HUML, so if the behaviour that was just described causes duplicate keys, the function will fail.

When encoding, if a Lua table contains itself or a parent node, it will simply be represented as the string «[recursive table]» because it’s impossible to traverse an infinite loop.