Browse Source

Merge pull request #47 from Flo12344/main

Fix for floating number not able to be parsed (Godot)
Annulus Games 1 year ago
parent
commit
2070b28af1

+ 1 - 1
src/Lua/CodeAnalysis/Syntax/Parser.cs

@@ -1010,7 +1010,7 @@ public ref struct Parser
         }
         }
         else
         else
         {
         {
-            return double.Parse(text);
+            return double.Parse(text, NumberStyles.Float, CultureInfo.InvariantCulture);
         }
         }
     }
     }
 }
 }

+ 2 - 1
src/Lua/LuaValue.cs

@@ -1,3 +1,4 @@
+using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 using Lua.Internal;
 using Lua.Internal;
@@ -120,7 +121,7 @@ public readonly struct LuaValue : IEquatable<LuaValue>
                     }
                     }
                     else
                     else
                     {
                     {
-                        var tryResult = double.TryParse(str, out var d);
+                        var tryResult = double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out var d);
                         result = tryResult ? Unsafe.As<double, T>(ref d) : default!;
                         result = tryResult ? Unsafe.As<double, T>(ref d) : default!;
                         return tryResult;
                         return tryResult;
                     }
                     }

+ 2 - 1
src/Lua/Standard/BasicLibrary.cs

@@ -1,3 +1,4 @@
+using System.Globalization;
 using Lua.CodeAnalysis.Compilation;
 using Lua.CodeAnalysis.Compilation;
 using Lua.Internal;
 using Lua.Internal;
 using Lua.Runtime;
 using Lua.Runtime;
@@ -445,7 +446,7 @@ public sealed class BasicLibrary
             }
             }
             else if (toBase == 10)
             else if (toBase == 10)
             {
             {
-                if (double.TryParse(str, out var result))
+                if (double.TryParse(str, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
                 {
                 {
                     value = result;
                     value = result;
                 }
                 }