Skip to content

Commit 8ef5a87

Browse files
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.
1 parent 7d3b05e commit 8ef5a87

43 files changed

Lines changed: 1526 additions & 648 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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 -AsObject
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 -AsObject
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/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.

src/data/Settings.psd1

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

src/finally.ps1

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

src/formats/CultureInfo.Format.ps1xml

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

0 commit comments

Comments
 (0)