Skip to content

Commit 6f752aa

Browse files
committed
Split off Lua library code into a partial
1 parent a2efccb commit 6f752aa

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Laylua;
5+
6+
public sealed partial class Lua
7+
{
8+
private readonly List<LuaLibrary> _openLibraries;
9+
10+
public bool OpenLibrary(LuaLibrary library)
11+
{
12+
foreach (var openLibrary in _openLibraries)
13+
{
14+
if (string.Equals(openLibrary.Name, library.Name, StringComparison.Ordinal))
15+
return false;
16+
}
17+
18+
library.Open(this, false);
19+
_openLibraries.Add(library);
20+
return true;
21+
}
22+
23+
public bool CloseLibrary(string libraryName)
24+
{
25+
for (var i = 0; i < _openLibraries.Count; i++)
26+
{
27+
var openLibrary = _openLibraries[i];
28+
if (string.Equals(openLibrary.Name, libraryName, StringComparison.Ordinal))
29+
{
30+
openLibrary.Close(this);
31+
_openLibraries.RemoveAt(i);
32+
return true;
33+
}
34+
}
35+
36+
return false;
37+
}
38+
}

src/Laylua/Library/Lua.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public object? this[string name]
6565

6666
internal LuaMarshaler Marshaler { get; }
6767

68-
private readonly List<LuaLibrary> _openLibraries;
69-
7068
public Lua()
7169
: this(LuaMarshaler.Default)
7270
{ }
@@ -113,35 +111,6 @@ private Lua(
113111
Globals = parent.Globals;
114112
}
115113

116-
public bool OpenLibrary(LuaLibrary library)
117-
{
118-
foreach (var openLibrary in _openLibraries)
119-
{
120-
if (string.Equals(openLibrary.Name, library.Name, StringComparison.Ordinal))
121-
return false;
122-
}
123-
124-
library.Open(this, false);
125-
_openLibraries.Add(library);
126-
return true;
127-
}
128-
129-
public bool CloseLibrary(string libraryName)
130-
{
131-
for (var i = 0; i < _openLibraries.Count; i++)
132-
{
133-
var openLibrary = _openLibraries[i];
134-
if (string.Equals(openLibrary.Name, libraryName, StringComparison.Ordinal))
135-
{
136-
openLibrary.Close(this);
137-
_openLibraries.RemoveAt(i);
138-
return true;
139-
}
140-
}
141-
142-
return false;
143-
}
144-
145114
[DoesNotReturn]
146115
internal static void ThrowLuaException(Lua lua)
147116
{

0 commit comments

Comments
 (0)