Skip to content

Add Import-Lua and Export-Lua file I/O functions #9

Description

The module currently exposes ConvertFrom-Lua and ConvertTo-Lua for string ↔ object conversion. Scripts working with .lua files need to combine these with Get-Content -Raw / Set-Content for every file operation.

Every other PowerShell serialization format ships file-I/O wrappers — Import-Csv / Export-Csv, Import-Clixml / Export-Clixml, Import-PowerShellDataFile. Users expect the same convenience for Lua tables.

Request

Desired capability

$config = Import-Lua -Path settings.lua
$config | Export-Lua -Path settings.lua
$config | Export-Lua -Path settings.lua -NoClobber

Standard parameters

Parameter Import-Lua Export-Lua Description
-Path File path (position 0)
-LiteralPath Literal path (no wildcard expansion)
-Encoding Default utf8NoBOM
-InputObject ValueFromPipeline
-NoClobber Fail if target exists
-Force Overwrite read-only files

All ConvertFrom-Lua / ConvertTo-Lua parameters pass through.

Acceptance criteria

  • Import-Lua -Path f.lua returns the same object as Get-Content f.lua -Raw | ConvertFrom-Lua
  • $o | Export-Lua -Path f.lua produces the same content as $o | ConvertTo-Lua | Set-Content f.lua
  • -NoClobber, -Force, -Encoding, -LiteralPath behave as in Export-Csv / Import-Csv
  • ShouldProcess support (-WhatIf, -Confirm) on Export-Lua
  • Round-trip via file: $o | Export-Lua -Path $f; Import-Lua -Path $f produces an equivalent object

Technical decisions

Architecture: Thin wrappers around ConvertFrom-Lua / ConvertTo-Lua. All format logic stays in the Convert functions.

Function placement: src/functions/public/Import-Lua.ps1 and src/functions/public/Export-Lua.ps1.

Parameter sets: Path (default, position 0) and LiteralPath, mirroring Import-Csv.

File I/O: Get-Content -Raw for Import; Set-Content for Export. Encoding handled via the standard -Encoding parameter.

Breaking changes: None. New functions only.


Implementation plan

  • Add Import-Lua in src/functions/public/Import-Lua.ps1
  • Add Export-Lua in src/functions/public/Export-Lua.ps1
  • Add tests/Import-Lua.Tests.ps1 — basic read, -Encoding, -LiteralPath, missing file
  • Add tests/Export-Lua.Tests.ps1 — basic write, -NoClobber, -Force, -Encoding, -WhatIf, pipeline input
  • Add round-trip test through file
  • Update examples/General.ps1 and README

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