Parsing single level yaml files into a Lua table
Given a yaml-like file containing key-value pairs like this:
key1: value1key2: value2key3: value3The following function will load it and return the data as a Lua table.
function read_yaml_file(filename) local file = io.open(filename, "r") if not file then return nil, "Failed to open file: " .. filename end
local data = {} for line in file:lines() do local key, value = line:match("(%w+):%s*(.+)") if key and value then data[key] = value end end
file:close() return dataendThis work is licensed under CC BY-NC-SA 4.0. Copying is an act of love — please copy!