Skip to content

Commit ccced51

Browse files
committed
don't throw disposal exceptions for #83
1 parent eaec70f commit ccced51

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

SomethingNeedDoing/LuaMacro/NLuaMacroEngine.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ private async Task ExecuteMacro(MacroInstance macro, CancellationToken externalT
8787
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(externalToken, macro.CancellationSource.Token);
8888
var token = linkedCts.Token;
8989

90+
Lua? lua = null;
9091
try
9192
{
9293
FrameworkLogger.Debug($"Starting Lua macro execution for macro {macro.Macro.Id}");
93-
using var lua = new Lua();
94+
lua = new Lua();
9495
lua.State.Encoding = Encoding.UTF8;
9596

9697
lua.LoadCLRPackage();
@@ -222,6 +223,20 @@ await Svc.Framework.RunOnTick(async () =>
222223
finally
223224
{
224225
_activeLuaEnvironments.Remove(macro.Macro.Id, out var _);
226+
227+
// Doing this manually since NLua is a very well written library
228+
if (lua != null)
229+
{
230+
try
231+
{
232+
lua.Dispose();
233+
}
234+
catch (Exception ex)
235+
{
236+
FrameworkLogger.Warning($"Error disposing Lua environment for macro {macro.Macro.Id}: {ex.Message}");
237+
}
238+
}
239+
225240
macro.Dispose();
226241
}
227242
}

0 commit comments

Comments
 (0)