22using System . Collections ;
33using System . Collections . Generic ;
44using System . Diagnostics ;
5+ using System . Runtime . CompilerServices ;
56using Laylua . Moon ;
67using Qommon ;
78
@@ -19,9 +20,34 @@ public unsafe partial class LuaTable
1920 public readonly struct SequenceCollection
2021 {
2122 /// <summary>
22- /// Gets the length of the sequence part.
23+ /// Gets the length of the sequence.
24+ /// This returns the same value as the length operator (<c>#table</c>).
2325 /// </summary>
24- public lua_Integer Length => _table . Length ;
26+ /// <remarks>
27+ /// <b>To get the number of key/value pairs in the table,
28+ /// use <see cref="Count"/> instead, as it works for all keys.</b>
29+ /// <para/>
30+ /// <inheritdoc cref="Add{T}"/>
31+ /// <br/>
32+ /// See <a href="https://www.lua.org/manual/5.4/manual.html#3.4.7">Lua manual</a>.
33+ /// </remarks>
34+ public lua_Integer Length
35+ {
36+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
37+ get
38+ {
39+ var lua = _table . Lua ;
40+ var L = lua . State . L ;
41+
42+ lua . Stack . EnsureFreeCapacity ( 1 ) ;
43+
44+ using ( lua . Stack . SnapshotCount ( ) )
45+ {
46+ lua . Stack . Push ( _table ) ;
47+ return luaL_len ( L , - 1 ) ;
48+ }
49+ }
50+ }
2551
2652 private readonly LuaTable _table ;
2753
@@ -34,7 +60,9 @@ internal SequenceCollection(LuaTable table)
3460 /// Adds the value at the end of the sequence.
3561 /// </summary>
3662 /// <remarks>
37- /// <inheritdoc cref="Add{T}"/>
63+ /// If the table is not a sequence,
64+ /// i.e. if the keys of the table are not consecutive integers,
65+ /// this might not return the expected result.
3866 /// </remarks>
3967 /// <param name="value"> The value to add. </param>
4068 public void Add < T > ( T value )
@@ -60,9 +88,9 @@ public void Add<T>(T value)
6088 /// <remarks>
6189 /// <inheritdoc cref="Add{T}"/>
6290 /// </remarks>
63- /// <param name="value"> The value to insert. </param>
6491 /// <param name="index"> The one-based index in the sequence. </param>
65- public void Insert < T > ( T value , lua_Integer index )
92+ /// <param name="value"> The value to insert. </param>
93+ public void Insert < T > ( lua_Integer index , T value )
6694 {
6795 var length = Length ;
6896 if ( index < 1 || index > length + 1 )
@@ -99,7 +127,7 @@ public void Insert<T>(T value, lua_Integer index)
99127 /// <inheritdoc cref="Add{T}"/>
100128 /// </remarks>
101129 /// <param name="index"> The one-based index in the sequence. </param>
102- public void RemoveAt ( int index )
130+ public void RemoveAt ( lua_Integer index )
103131 {
104132 var length = Length ;
105133 if ( index < 1 || index > length )
0 commit comments