Skip to content

v1.0.0

Choose a tag to compare

@github-actions github-actions released this 16 Apr 06:42
· 1 commit to main since this release
e070ac5

🌟 [Release]: PowerShell-Lua data conversion now available via ConvertTo-Lua and ConvertFrom-Lua (#3)

PowerShell objects can now be serialized to Lua table constructor strings and deserialized back — enabling round-trip data conversion between PowerShell and Lua configuration files. This is useful for managing configuration data in Lua-based applications such as World of Warcraft addons (e.g., ElvUI).

  • Fixes #2

New: ConvertTo-Lua — serialize PowerShell objects to Lua

ConvertTo-Lua converts hashtables, ordered dictionaries, PSCustomObjects, arrays, and primitives into valid Lua table constructor strings per the Lua 5.4 grammar §3.4.9.

@{ name = "ElvUI"; version = "13.74"; enabled = $true } | ConvertTo-Lua
# Output:
# {
#     enabled = true,
#     name = "ElvUI",
#     version = "13.74"
# }

# Compressed output
@(1, 2, 3) | ConvertTo-Lua -Compress
# Output: {1,2,3}

Parameters:

Parameter Description
-InputObject Any PowerShell object (mandatory, accepts pipeline input)
-Depth Max recursion depth (default 2, range 0–100). Warns when exceeded
-Compress Omit whitespace and indentation
-EnumsAsStrings Serialize enum values as string names instead of numeric values
-AsArray Always wrap output in a Lua sequence table, even for a single value

Properties with $null values are omitted from output (per Lua's nil-means-absent semantics). Keys use bare identifiers when valid per Lua grammar; bracket-quote notation otherwise.

New: ConvertFrom-Lua — deserialize Lua table strings to PowerShell objects

ConvertFrom-Lua parses Lua table constructor strings into PSCustomObject by default, or ordered hashtable with -AsHashtable.

'{ server = "localhost", port = 8080 }' | ConvertFrom-Lua
# Output: PSCustomObject with .server and .port properties

# Round-trip fidelity
'{1, 2, 3}' | ConvertFrom-Lua -NoEnumerate | ConvertTo-Lua -Compress
# Output: {1,2,3}

Parameters:

Parameter Description
-InputObject A Lua table constructor string (mandatory, accepts pipeline input)
-AsHashtable Output [ordered] hashtable instead of PSCustomObject
-Depth Max nesting depth allowed in input (default 1024). Throws on violation
-NoEnumerate Output arrays as a single [object[]] without pipeline enumeration

Supported Lua data types: tables (sequence, key-value, mixed, nested, empty), strings (double-quoted, single-quoted, long strings with all escape sequences), numbers (integer, float, hex, scientific notation), booleans, and nil.

Lua comments (single-line -- and multi-line --[[ ]]) are correctly ignored during parsing.

Technical Details

  • Template files removed: All placeholder files from the PSModule template (Book.ps1, SecretWriter.ps1, Get-PSModuleTest.ps1, New-PSModuleTest.ps1, Set-PSModuleTest.ps1, Test-PSModuleTest.ps1, format/type XML files, data files, variables, etc.) replaced with actual module implementation.
  • Public functions: src/functions/public/Lua/ConvertTo-Lua.ps1 and src/functions/public/Lua/ConvertFrom-Lua.ps1 — thin wrappers handling pipeline input, parameter validation, and -AsArray/-NoEnumerate behavior.
  • Private functions: ConvertTo-LuaTable.ps1 (recursive serializer with depth tracking and 4-space indent), ConvertFrom-LuaTable.ps1 (recursive-descent parser with script-scoped state), Format-LuaKey.ps1 (Lua identifier validation against pattern [a-zA-Z_][a-zA-Z0-9_]* and reserved word list).
  • Parser: Pure PowerShell recursive-descent parser — no external DLL or .NET assembly dependency. Tracks nesting depth and throws when -Depth is exceeded.
  • Tests: 1,158 lines of Pester tests in tests/Lua.Tests.ps1 covering all Lua data types, comment handling, reserved words as keys, depth limits, parameter switches, round-trip conversion, and error cases. Test data files in tests/data/ (Lua/JSON pairs) for complex structure validation.
  • README: Updated with module description, installation instructions, and usage examples.
  • 45 files changed, 2,620 insertions, 648 deletions.