Browse Source

Fix: LuaValue.TryRead

AnnulusGames 1 year ago
parent
commit
008ad02fc3
1 changed files with 13 additions and 1 deletions
  1. 13 1
      src/Lua/LuaValue.cs

+ 13 - 1
src/Lua/LuaValue.cs

@@ -84,8 +84,20 @@ public readonly struct LuaValue : IEquatable<LuaValue>
                     var str = (string)referenceValue!;
                     var span = str.AsSpan().Trim();
 
+                    if (span.Length == 0)
+                    {
+                        result = default!;
+                        return false;
+                    }
+
                     var sign = 1;
-                    if (span.Length > 0 && span[0] == '-')
+                    var first = span[0];
+                    if (first is '+')
+                    {
+                        sign = 1;
+                        span = span[1..];
+                    }
+                    else if (first is '-')
                     {
                         sign = -1;
                         span = span[1..];