Class StructureReader
StructureReader is an object that can read some structured-text config or data files.
Here is a short example of structure. This is format is more human readable than CSV, and is used by Harmony Assistant for some config files, so it follows the same syntax.
DebutFruits DebutFruit Name Apple Url https://en.wikipedia.org/wiki/Apple Color Green Yellow Red FinFruit DebutFruit Name Banana Color Yellow FinFruit FinFruits
- Example
Include "SMStructureReader" local sr = StructureReader.loadFile("/path/to/fruits.txt") local fruit = sr:next("Fruit") local cpt = 0 while fruit do print(fruit:get("Name")) fruit = sr:next("Fruit") end print("Fruits found:" .. cpt) sr:rewind() -- go back to begining (top of the file) local vegetable = sr:next("Vegetable") if vegetable == nil then print("No vegetable found."); end
Summary
Return type | Function and summary |
---|---|
string | get(string key) Get the value of a property of the structure. |
StructureReader | next(string structName) Locate the next structure between Debut[structName] and Fin[structName] The returned value is a StructureReader as structures may be organized in tree. |
rewind() Go back to the beginning of the structure, if a search reached the end. |
Methods
StructureReader:next(string structName)
Locate the next structure between Debut[structName] and Fin[structName] The returned value is a StructureReader as structures may be organized in tree.
Parameter | Type | Default | Description |
---|---|---|---|
structName | string | structName |
- Return
- StructureReader: StructureReader
StructureReader:get(string key)
Get the value of a property of the structure.
Parameter | Type | Default | Description |
---|---|---|---|
key | string | key |
- Return
- string: string
StructureReader:rewind()
Go back to the beginning of the structure, if a search reached the end.