Skip to content

Commit e070ac5

Browse files
🌟 [Release]: PowerShell-Lua data conversion now available via ConvertTo-Lua and ConvertFrom-Lua (#3)
* Add Lua conversion functions and corresponding tests - Implemented ConvertTo-Lua and ConvertFrom-Lua functions for converting PowerShell objects to Lua table strings and vice versa. - Added helper functions ConvertTo-LuaTable and Format-LuaKey for internal processing. - Created comprehensive tests for both conversion functions, covering various data types including primitives, strings, arrays, and tables. - Included test data files for validation of string and array conversions. - Ensured proper handling of comments and special characters in Lua syntax. * Add ConvertTo-Lua and ConvertFrom-Lua with tests and test data * Bump PSModule/Process-PSModule/.github/workflows/workflow.yml (#1) Bumps [PSModule/Process-PSModule/.github/workflows/workflow.yml](https://github.com/psmodule/process-psmodule) from 5.4.3 to 5.4.7. - [Release notes](https://github.com/psmodule/process-psmodule/releases) - [Commits](PSModule/Process-PSModule@60bdf8a...1111791) --- updated-dependencies: - dependency-name: PSModule/Process-PSModule/.github/workflows/workflow.yml dependency-version: 5.4.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Refactor Lua conversion functions and add new parsing capabilities - Improved string escaping in ConvertTo-LuaTable for better handling of special characters. - Enhanced depth warning messages for better clarity. - Simplified parameter passing in ConvertTo-LuaTable calls. - Updated ConvertFrom-Lua to use array syntax for output. - Refactored ConvertTo-Lua to improve readability and maintainability. - Removed obsolete header and manifest files. - Updated tests for better clarity and consistency. - Added new Lua parsing functions: Read-LuaHexFloat, Read-LuaMultiLineString, Read-LuaNumber, Read-LuaString, Read-LuaTable, Read-LuaValue, and Skip-LuaWhitespace for comprehensive Lua support. - Adjusted data files to conform to new structure and formatting. * Fix negative value handling in Read-LuaHexFloat and Read-LuaNumber; improve formatting in Lua.Tests * Improve formatting in complex deep structure round-trip tests * Refactor Lua conversion functions and improve error handling; update examples for ConvertFrom-Lua * Add support for parsing assignment statements in ConvertFrom-Lua; enhance tests for various assignment scenarios * Format JSON files for improved readability in Assignments.json and WoWSavedVariables.json * Enhance type handling in ConvertTo-LuaTable; improve parsing logic in Read-LuaTable and update output types in ConvertFrom-LuaTable * Add .luacheckrc configuration to allow defined top for Lua test files * Update .luacheckrc to ignore test data files and clarify their purpose * Enhance error handling in Read-LuaString and Read-LuaTable; validate escape sequences and ensure table keys are not nil * Address PR review feedback * Fix string quotation for error message in Skip-LuaWhitespace function * Address PR review feedback * Address PR review feedback * Address PR review feedback * Address PR review feedback * Address PR review feedback - Assignment parser now accepts semicolons between statements (A = 1; B = 2) - Assignment-detection lookahead uses Skip-LuaWhitespace to handle comments between identifier and '=' - Added tests for both scenarios * Address PR review feedback: throw on unexpected end of input in Read-LuaValue * Address PR review feedback: update help text for long-bracket support, optimize comment skipping * Address PR review feedback: use strict null assertions for nil tests * Bump PSModule/Process-PSModule/.github/workflows/workflow.yml (#4) Bumps [PSModule/Process-PSModule/.github/workflows/workflow.yml](https://github.com/psmodule/process-psmodule) from 5.4.3 to 5.4.7. - [Release notes](https://github.com/psmodule/process-psmodule/releases) - [Commits](PSModule/Process-PSModule@60bdf8a...1111791) --- updated-dependencies: - dependency-name: PSModule/Process-PSModule/.github/workflows/workflow.yml dependency-version: 5.4.7 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 7d3b05e commit e070ac5

60 files changed

Lines changed: 3429 additions & 658 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[codespell]
22
skip = ./.github/linters
3-
ignore-words-list = afterall
3+
ignore-words-list = afterall,simpy
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Test data files are Lua data/config files (e.g. WoW SavedVariables format)
2+
-- that define top-level globals and are not executed as scripts.
3+
files["**/tests/data/Assignments.lua"].ignore = {"111", "112"}
4+
files["**/tests/data/WoWSavedVariables.lua"].ignore = {"111", "112"}

‎.github/workflows/Process-PSModule.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ permissions:
2727

2828
jobs:
2929
Process-PSModule:
30-
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@60bdf8a5a4c92c53fcf2a8d23f7d5f5c93e6864e # v5.4.3
30+
uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@11117919e65242d3388727819a751f74ad24ea9e # v5.5.0
3131
secrets:
3232
APIKEY: ${{ secrets.APIKEY }}

‎README.md‎

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,106 @@
1-
# {{ NAME }}
1+
# Lua
22

3-
{{ DESCRIPTION }}
3+
A PowerShell module for converting between PowerShell objects and Lua table notation.
44

55
## Prerequisites
66

77
This uses the following external resources:
8+
89
- The [PSModule framework](https://github.com/PSModule/Process-PSModule) for building, testing and publishing the module.
910

1011
## Installation
1112

1213
To install the module from the PowerShell Gallery, you can use the following command:
1314

1415
```powershell
15-
Install-PSResource -Name {{ NAME }}
16-
Import-Module -Name {{ NAME }}
16+
Install-PSResource -Name Lua
17+
Import-Module -Name Lua
1718
```
1819

1920
## Usage
2021

21-
Here is a list of example that are typical use cases for the module.
22+
Here is a list of examples that are typical use cases for the module.
23+
24+
### Example 1: Convert a PowerShell hashtable to Lua
25+
26+
```powershell
27+
@{ name = "ElvUI"; version = "13.74"; enabled = $true } | ConvertTo-Lua
28+
29+
{
30+
name = "ElvUI",
31+
version = "13.74",
32+
enabled = true
33+
}
34+
```
35+
36+
### Example 2: Convert a Lua table string to a PowerShell object
37+
38+
```powershell
39+
$lua = '{ name = "ElvUI", version = "13.74", enabled = true }'
40+
$config = $lua | ConvertFrom-Lua
41+
$config.name # ElvUI
42+
$config.enabled # True
43+
```
44+
45+
### Example 3: Read a Lua file and convert to PowerShell
2246

23-
### Example 1: Greet an entity
47+
```powershell
48+
$luaContent = Get-Content -Path 'config.lua' -Raw
49+
$config = ConvertFrom-Lua -InputObject $luaContent
50+
$config.unitframes.playerWidth # 270
51+
```
2452

25-
Provide examples for typical commands that a user would like to do with the module.
53+
### Example 4: Convert a PowerShell object to compressed Lua
2654

2755
```powershell
28-
Greet-Entity -Name 'World'
29-
Hello, World!
56+
@(1, 2, 3) | ConvertTo-Lua -Compress
57+
58+
{1,2,3}
3059
```
3160

32-
### Example 2
61+
### Example 5: Round-trip JSON to Lua
62+
63+
```powershell
64+
$data = Get-Content -Path 'settings.json' -Raw | ConvertFrom-Json
65+
$luaOutput = $data | ConvertTo-Lua
66+
$luaOutput | Set-Content -Path 'settings.lua'
67+
```
3368

34-
Provide examples for typical commands that a user would like to do with the module.
69+
### Example 6: Convert Lua to PSCustomObject
3570

3671
```powershell
37-
Import-Module -Name PSModuleTemplate
72+
$result = '{ server = "localhost", port = 8080 }' | ConvertFrom-Lua
73+
$result.server # localhost
74+
$result.port # 8080
3875
```
3976

4077
### Find more examples
4178

4279
To find more examples of how to use the module, please refer to the [examples](examples) folder.
4380

44-
Alternatively, you can use the Get-Command -Module 'This module' to find more commands that are available in the module.
45-
To find examples of each of the commands you can use Get-Help -Examples 'CommandName'.
81+
Alternatively, you can use `Get-Command -Module 'Lua'` to find commands available in the module.
82+
To find examples of each command, use `Get-Help -Examples 'CommandName'`.
4683

4784
## Documentation
4885

49-
Link to further documentation if available, or describe where in the repository users can find more detailed documentation about
50-
the module's functions and features.
86+
For detailed documentation on each function, use the built-in help system:
87+
88+
```powershell
89+
Get-Help ConvertTo-Lua -Full
90+
Get-Help ConvertFrom-Lua -Full
91+
```
5192

5293
## Contributing
5394

5495
Coder or not, you can contribute to the project! We welcome all contributions.
5596

56-
### For Users
97+
### For users
5798

5899
If you don't code, you still sit on valuable information that can make this project even better. If you experience that the
59100
product does unexpected things, throw errors or is missing functionality, you can help by submitting bugs and feature requests.
60101
Please see the issues tab on this project and submit a new issue that matches your needs.
61102

62-
### For Developers
103+
### For developers
63104

64105
If you do code, we'd love to have your contributions. Please read the [Contribution guidelines](CONTRIBUTING.md) for more information.
65106
You can either help by picking up an existing issue or submit a new one if you have an idea for a new feature or improvement.
66-
67-
## Acknowledgements
68-
69-
Here is a list of people and projects that helped this project in some way.

‎examples/General.ps1‎

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
11
<#
2-
.SYNOPSIS
3-
This is a general example of how to use the module.
2+
.SYNOPSIS
3+
Examples of how to use the Lua module.
44
#>
55

66
# Import the module
7-
Import-Module -Name 'PSModule'
7+
Import-Module -Name 'Lua'
88

9-
# Define the path to the font file
10-
$FontFilePath = 'C:\Fonts\CodeNewRoman\CodeNewRomanNerdFontPropo-Regular.tff'
9+
# Convert a PowerShell hashtable to Lua table notation
10+
$config = [ordered]@{
11+
name = 'ElvUI'
12+
version = '13.74'
13+
enabled = $true
14+
scaling = 0.85
15+
authors = @('Elv', 'Simpy', 'Blazeflack')
16+
}
17+
$luaOutput = $config | ConvertTo-Lua
18+
Write-Output $luaOutput
1119

12-
# Install the font
13-
Install-Font -Path $FontFilePath -Verbose
20+
# Convert a Lua table string to a PowerShell object
21+
$luaString = @'
22+
{
23+
name = "ElvUI",
24+
version = "13.74",
25+
enabled = true,
26+
unitframes = {
27+
playerWidth = 270,
28+
playerHeight = 54
29+
}
30+
}
31+
'@
32+
$result = $luaString | ConvertFrom-Lua
33+
Write-Output "Name: $($result.name)"
34+
Write-Output "Player Width: $($result.unitframes.playerWidth)"
1435

15-
# List installed fonts
16-
Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular'
36+
# Convert Lua to PSCustomObject
37+
$obj = '{ server = "localhost", port = 8080 }' | ConvertFrom-Lua
38+
Write-Output "Server: $($obj.server), Port: $($obj.port)"
39+
40+
# Compressed output
41+
$compressed = @(1, 2, 3, 4, 5) | ConvertTo-Lua -Compress
42+
Write-Output "Compressed: $compressed"
1743

18-
# Uninstall the font
19-
Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular' | Uninstall-Font -Verbose

‎src/README.md‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎src/assemblies/LsonLib.dll‎

-42.5 KB
Binary file not shown.

‎src/classes/private/SecretWriter.ps1‎

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎src/classes/public/Book.ps1‎

Lines changed: 0 additions & 147 deletions
This file was deleted.

‎src/data/Config.psd1‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)