Skip to content

Add Format-Lua function for normalization #7

Description

Hand-written or machine-generated Lua table files often have inconsistent indentation, spacing, and key-quoting. A Format-Lua function normalizes the text without changing semantics — equivalent to ConvertFrom-Lua | ConvertTo-Lua but expressed as a single ergonomic call. Sister modules already follow this pattern: Format-Json and Format-Hashtable.

Request

Desired capability

Get-Content settings.lua -Raw | Format-Lua
Format-Lua -Path settings.lua -Indent 4

Parameters

Parameter Description
-InputObject String to format (ValueFromPipeline, default set)
-Path File path to read and format
-LiteralPath Literal file path
-Indent Spaces per level (default: 2)
-Compress Single-line / minimal-whitespace output

Acceptance criteria

  • Format-Lua $s produces canonical-form Lua for $s
  • Idempotent: Format-Lua (Format-Lua $s) equals Format-Lua $s
  • -Compress produces a single-line representation
  • -Indent controls spacing between nesting levels
  • Output remains parseable by ConvertFrom-Lua

Technical decisions

Implementation: Parses input with ConvertFrom-Lua and re-emits with ConvertTo-Lua using the requested indentation. Reuses existing logic — no new parser or emitter.

Function placement: src/functions/public/Format-Lua.ps1.

Parameter sets: InputObject (default, pipeline) and Path / LiteralPath for file input.


Implementation plan

  • Add Format-Lua in src/functions/public/Format-Lua.ps1
  • Add Pester tests — basic format, custom -Indent, -Compress, idempotent round-trip
  • Update README and examples/General.ps1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions