Skip to content

Commit 2070b28

Browse files
authored
Merge pull request #47 from Flo12344/main
Fix for floating number not able to be parsed (Godot)
2 parents b3b7d8d + 6c16970 commit 2070b28

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/Lua/CodeAnalysis/Syntax/Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ static double ConvertTextToNumber(ReadOnlySpan<char> text)
10101010
}
10111011
else
10121012
{
1013-
return double.Parse(text);
1013+
return double.Parse(text, NumberStyles.Float, CultureInfo.InvariantCulture);
10141014
}
10151015
}
10161016
}

src/Lua/LuaValue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using System.Runtime.CompilerServices;
23
using System.Runtime.InteropServices;
34
using Lua.Internal;
@@ -120,7 +121,7 @@ public bool TryRead<T>(out T result)
120121
}
121122
else
122123
{
123-
var tryResult = double.TryParse(str, out var d);
124+
var tryResult = double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out var d);
124125
result = tryResult ? Unsafe.As<double, T>(ref d) : default!;
125126
return tryResult;
126127
}

src/Lua/Standard/BasicLibrary.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using Lua.CodeAnalysis.Compilation;
23
using Lua.Internal;
34
using Lua.Runtime;
@@ -445,7 +446,7 @@ public ValueTask<int> ToNumber(LuaFunctionExecutionContext context, Memory<LuaVa
445446
}
446447
else if (toBase == 10)
447448
{
448-
if (double.TryParse(str, out var result))
449+
if (double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
449450
{
450451
value = result;
451452
}

0 commit comments

Comments
 (0)