Sort Lines
Sorts JSONL (one-JSON-per-line) files alphabetically by their `name` field, primarily used for audio definition files.
Sorts JSONL (one-JSON-per-line) files alphabetically by their name field, primarily used for audio definition files.
Overview
util_sortLines reads files where each line is a JSON object, sorts them by the name field, and rewrites the file in sorted order. Provides a convenience function to process all JSON files in a level's Audio directory.
Module path: lua/ge/extensions/util/sortLines.lua
Note: Plain module (no extension hooks), used via require or extensions.util_sortLines.
Exports (M)
| Function | Signature | Description |
|---|---|---|
handleFile | (path) | Reads a JSONL file, sorts lines by name, rewrites the file. |
handleLevel | (level) | Processes all .json files in /levels/<level>/main/MissionGroup/Audio/. |
Internals
Sorting
Each line is parsed via jsonDecode(line). Lines are sorted by obj.name (or "" if no name). Empty lines are discarded on rewrite.
File I/O
Uses readFile(path) to read, io.open(path, 'w') to rewrite. Each non-empty sorted line is written with a trailing newline.
How It Works
- Call
handleFile(path)with a JSONL file path. - Each line is decoded, paired with its
name, and sorted alphabetically. - The file is overwritten with sorted lines.
Lua Examples
local sortLines = extensions.util_sortLines
-- Sort a specific file
sortLines.handleFile('/levels/east_coast_usa/main/MissionGroup/Audio/sounds.json')
-- Sort all audio files for a level
sortLines.handleLevel('east_coast_usa')Additional Exports
M.handleFile- (undocumented)M.handleLevel- (undocumented)