Skip to content

Commit 18ece06

Browse files
Enhance type handling in ConvertTo-LuaTable; improve parsing logic in Read-LuaTable and update output types in ConvertFrom-LuaTable
1 parent 85fe075 commit 18ece06

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/functions/private/ConvertFrom-LuaTable.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
engine used by ConvertFrom-Lua.
1010
#>
1111
[OutputType([object])]
12+
[OutputType([System.Collections.Specialized.OrderedDictionary])]
1213
[CmdletBinding()]
1314
param(
1415
# The Lua table string to parse.
@@ -40,7 +41,7 @@
4041
$script:luaString.Substring($script:luaPos, 6) -ceq 'return') {
4142
$nextPos = $script:luaPos + 6
4243
if ($nextPos -ge $script:luaString.Length -or
43-
$script:luaString[$nextPos] -match '[\s{]') {
44+
$script:luaString[$nextPos] -notmatch '[a-zA-Z0-9_]') {
4445
$script:luaPos = $nextPos
4546
Skip-LuaWhitespace
4647
}

src/functions/private/ConvertTo-LuaTable.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@
6161
$escaped = $InputObject.ToString() -replace '\\', '\\\\' -replace '"', '\"'
6262
return "`"$escaped`""
6363
}
64-
return ([int]$InputObject).ToString([System.Globalization.CultureInfo]::InvariantCulture)
64+
$underlyingType = [System.Enum]::GetUnderlyingType($InputObject.GetType())
65+
if ($underlyingType -eq [byte] -or
66+
$underlyingType -eq [uint16] -or
67+
$underlyingType -eq [uint32] -or
68+
$underlyingType -eq [uint64]) {
69+
return ([System.Convert]::ToUInt64($InputObject)).ToString([System.Globalization.CultureInfo]::InvariantCulture)
70+
}
71+
return ([System.Convert]::ToInt64($InputObject)).ToString([System.Globalization.CultureInfo]::InvariantCulture)
6572
}
6673

6774
if ($InputObject -is [int] -or $InputObject -is [long] -or

src/functions/private/Read-LuaTable.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
}
3737

3838
# Check for bracket key: ["key"] = value or [expr] = value
39+
# When [ is followed by [ or =, it's a long-bracket string value, not a bracket key
3940
if ($script:luaString[$script:luaPos] -eq '[' -and
4041
$script:luaPos + 1 -lt $script:luaString.Length -and
41-
$script:luaString[$script:luaPos + 1] -ne '[') {
42+
$script:luaString[$script:luaPos + 1] -ne '[' -and
43+
$script:luaString[$script:luaPos + 1] -ne '=') {
4244
$script:luaPos++ # skip [
4345
Skip-LuaWhitespace
4446
$key = Read-LuaValue

0 commit comments

Comments
 (0)