Skip to content

Support variadic Lua arguments with ReadOnlySpan/ReadOnlyMemory - #255

Merged
akeit0 merged 3 commits into
mainfrom
feature/params-like-support
Oct 10, 2026
Merged

akeit0 merged 3 commits into
mainfrom
feature/params-like-support

Conversation

@akeit0

@akeit0 akeit0 commented Jan 18, 2026 •

Copy link
Copy Markdown
Collaborator

Generated LuaObject bindings can now pass the remaining Lua arguments to a final ReadOnlySpan or ReadOnlyMemory parameter, optionally followed by an injected CancellationToken. For example, an instance method Sum(double first, ReadOnlySpan rest) called as obj:Sum(1, 2, 3) receives first = 1 and rest = [2, 3]. This removes the need for a handwritten LuaFunction wrapper for variadic C# methods.

The view excludes the instance receiver and consumed fixed arguments. Out parameters consume no Lua arguments, zero remaining arguments produces an empty view, and nil values remain present. Missing optional fixed arguments, ref/out return values, inherited methods and index/newindex/call metamethods are covered. Parameter classification is guarded for token-only methods, uses the existing ArgumentsMemory API, and keeps unsupported signatures as located diagnostics.

ReadOnlyMemory supports reading the arguments after await while the host call is active. Both types borrow the Lua stack; copy with ToArray() to retain values after returning. Only by-value views with LuaValue elements in the final non-token position are supported. Mutable views and C# params LuaValue[] remain unsupported. The README documents usage and lifetime constraints. No runtime/VM/API changes are required.

Validation:

  • 69 source-generator tests passed, including 28 new signature/diagnostic cases.
  • 419 runtime tests passed with TestCategory!=ExpectedFailure, including 22 new execution cases.
  • Release builds of netstandard2.1, net6.0, net8.0 and net10.0 passed with warnings treated as errors; CSharpier checked all 248 files and the diff against main passed git diff --check.
  • Unity 6000.5.5f1 live internal project, via modern unity CLI/Pipeline: the actual generator compiled Span/Memory bindings; empty arguments, instance slicing, nil, ref/out, optional prefixes, Memory across Task.Yield and token injection executed correctly. Temporary assets were removed, original DLL/PDB hashes restored and the project recompiled cleanly.
  • Local cost probe: warmed, cached static functions with three arguments, 100,000 calls per sample, median of nine samples, .NET 8 on Windows with tiered compilation disabled. Handwritten/generated Span bindings took 4.49/4.55 ms; handwritten/generated Memory bindings took 4.73/4.60 ms. Every measured case allocated 0 bytes during the loop. This is a narrow binding comparison; timings are not a general interpreter speedup claim.

Related: #150 and #254.

@akeit0
akeit0 requested a review from nuskey8 January 18, 2026 04:32
@akeit0
akeit0 marked this pull request as draft May 1, 2026 05:53
@akeit0 akeit0 changed the title Feature: params like support in SourceGenarator Support variadic Lua arguments with ReadOnlySpan/ReadOnlyMemory Oct 10, 2026
@akeit0
akeit0 marked this pull request as ready for review October 10, 2026 12:46
@akeit0
akeit0 removed the request for review from nuskey8 October 10, 2026 12:48
@akeit0
akeit0 merged commit 662e814 into main Oct 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant