Skip to content

Commit 4bb982c

Browse files
committed
Internalize dispose bools
1 parent 8491631 commit 4bb982c

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

src/Laylua.Tests/Tests/Marshaler/LuaMarshalerDelegateTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using System.Reflection;
23

34
namespace Laylua.Tests;
45

@@ -207,7 +208,7 @@ public void Delegate_LuaReference_DisposesLuaReference()
207208

208209
// Assert
209210
Assert.That(reference, Is.Not.Null);
210-
Assert.That(LuaReference.IsAlive(reference!), Is.False);
211+
Assert.That(IsReferenceAlive(reference), Is.False);
211212
}
212213

213214
[Test]
@@ -221,13 +222,19 @@ public void Delegate_ParamsObject_DisposesLuaReferences()
221222

222223
// Assert
223224
Assert.That(_references, Is.Not.Null);
224-
Assert.That(_references!.Select(LuaReference.IsAlive), Is.All.False);
225+
Assert.That(_references!.Select(IsReferenceAlive), Is.All.False);
225226
}
226227

227228
// Can't be local, because params doesn't work in local methods.
228229
private LuaReference[]? _references;
230+
229231
private void ParamsObjectMethod(params object[] args)
230232
{
231233
_references = args.OfType<LuaReference>().ToArray();
232234
}
235+
236+
private static bool IsReferenceAlive(LuaReference? reference)
237+
{
238+
return (bool) typeof(LuaReference).GetMethod("IsAlive", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, [reference])!;
239+
}
233240
}

src/Laylua/Library/Entities/Reference/LuaReference.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,7 @@ internal static void ValidateOwnership(Lua lua, LuaReference reference)
253253
}
254254
}
255255

256-
/// <summary>
257-
/// Checks whether the specified reference is alive,
258-
/// i.e. is initialized and not disposed.
259-
/// </summary>
260-
/// <param name="reference"> The reference to check. </param>
261-
/// <returns>
262-
/// <see langword="true"/> if the reference is initialized and not disposed.
263-
/// </returns>
264-
public static bool IsAlive(LuaReference reference)
256+
internal static bool IsAlive(LuaReference reference)
265257
{
266258
var lua = reference._lua;
267259
return lua != null && !lua.IsDisposed && !reference._isDisposed;

src/Laylua/Library/Lua.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ public object? this[string name]
6161
set => SetGlobal(name, value);
6262
}
6363

64-
/// <summary>
65-
/// Gets whether this instance is disposed.
66-
/// </summary>
67-
public bool IsDisposed => State.IsDisposed;
64+
internal bool IsDisposed => State.IsDisposed;
6865

6966
internal LuaMarshaler Marshaler { get; }
7067

src/Laylua/Moon/LuaState.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ public LuaGC GC
8686
}
8787
}
8888

89-
/// <summary>
90-
/// Gets whether this instance is disposed.
91-
/// </summary>
92-
public bool IsDisposed => _L == null;
89+
internal bool IsDisposed => _L == null;
9390

9491
internal object? State
9592
{

0 commit comments

Comments
 (0)