-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVMPool.cs
More file actions
22 lines (20 loc) · 706 Bytes
/
VMPool.cs
File metadata and controls
22 lines (20 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
namespace LuaMCP {
public class VMPool : IDisposable
{
private readonly Dictionary<string, LuaEngine> _luaEngines = [];
public string PrepareId(string? id) => id switch {
string s when s.Trim().Length > 0 => s,
_ => Guid.NewGuid().ToString() // whitespace/empty string or null
};
public LuaEngine GetOrCreate(string name)
{
if (_luaEngines.TryGetValue(name, out var engine)) return engine;
return _luaEngines[name] = new LuaEngine();
}
public void Dispose()
{
foreach (var engine in _luaEngines.Values) engine.Dispose();
_luaEngines.Clear();
}
}
}