Remove types that have been registered when unloading
This commit is contained in:
+10
-3
@@ -23,10 +23,11 @@ using System.Threading.Tasks;
|
|||||||
using Barotrauma.LuaCs;
|
using Barotrauma.LuaCs;
|
||||||
using Barotrauma.LuaCs.Events;
|
using Barotrauma.LuaCs.Events;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Barotrauma.LuaCs;
|
namespace Barotrauma.LuaCs;
|
||||||
|
|
||||||
class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService, IEventAssemblyUnloading
|
||||||
{
|
{
|
||||||
public Script? InternalScript => _script;
|
public Script? InternalScript => _script;
|
||||||
|
|
||||||
@@ -463,8 +464,6 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
|||||||
|
|
||||||
_script = null;
|
_script = null;
|
||||||
|
|
||||||
// todo unregister everything
|
|
||||||
|
|
||||||
return FluentResults.Result.Ok();
|
return FluentResults.Result.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,4 +508,12 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService
|
|||||||
|
|
||||||
return _script.Globals[tableName];
|
return _script.Globals[tableName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnAssemblyUnloading(Assembly assembly)
|
||||||
|
{
|
||||||
|
foreach (Type type in assembly.SafeGetTypes())
|
||||||
|
{
|
||||||
|
UserData.UnregisterType(type, deleteHistory: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user