Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.DS_Store
.idea/
4 changes: 2 additions & 2 deletions src/Lua/LuaFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Lua;

public class LuaFunction(string name, Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func)
{
public string Name { get; } = name;
public string Name { get; set; } = name;
internal Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> Func { get; } = func;

public LuaFunction(Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func) : this("anonymous", func)
Expand All @@ -31,4 +31,4 @@ public async ValueTask<int> InvokeAsync(LuaFunctionExecutionContext context, Mem
context.Thread.PopCallStackFrame();
}
}
}
}
5 changes: 3 additions & 2 deletions src/Lua/Runtime/Tracebacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ internal SourcePosition LastPosition
if (lastFunc is Closure closure)
{
var p = closure.Proto;
return p.SourcePositions[frame.CallerInstructionIndex];
if (frame.CallerInstructionIndex < p.SourcePositions.Length)
return p.SourcePositions[frame.CallerInstructionIndex];
}
}

Expand Down Expand Up @@ -66,4 +67,4 @@ public override string ToString()

return list.AsSpan().ToString();
}
}
}
9 changes: 8 additions & 1 deletion src/Lua/Standard/StringLibrary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text;
using Lua.Internal;
using System.Globalization;

namespace Lua.Standard;

Expand Down Expand Up @@ -148,6 +149,9 @@ public ValueTask<int> Find(LuaFunctionExecutionContext context, Memory<LuaValue>

public async ValueTask<int> Format(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
{
var currentCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

var format = context.GetArgument<string>(0);

// TODO: pooling StringBuilder
Expand Down Expand Up @@ -419,6 +423,9 @@ public async ValueTask<int> Format(LuaFunctionExecutionContext context, Memory<L


buffer.Span[0] = builder.ToString();

CultureInfo.CurrentCulture = currentCulture;

return 1;
}

Expand Down Expand Up @@ -629,4 +636,4 @@ public ValueTask<int> Upper(LuaFunctionExecutionContext context, Memory<LuaValue
buffer.Span[0] = s.ToUpper();
return new(1);
}
}
}
3 changes: 1 addition & 2 deletions tests/Lua.Tests/tests-lua/strings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ assert(string.format("%c",34)..string.format("%c",48)..string.format("%c",90)..s
string.format("%c%c%c%c", 34, 48, 90, 100))
assert(string.format("%s\0 is not \0%s", 'not be', 'be') == 'not be\0 is not \0be')
assert(string.format("%%%d %010d", 10, 23) == "%10 0000000023")
print("10.3 as string is: " .. string.format("%f", 10.3) .. " and as number: " .. tostring(tonumber(string.format("%f", 10.3))))
assert(tonumber(string.format("%f", 10.3)) == 10.3)
x = string.format('"%-50s"', 'a')
assert(#x == 52)
Expand Down Expand Up @@ -280,5 +281,3 @@ assert(os.setlocale(nil, "numeric") == 'C')
end

print('OK')