diff --git a/src/LuaPlugin.cs b/src/LuaPlugin.cs index b54cc83..b09c11a 100644 --- a/src/LuaPlugin.cs +++ b/src/LuaPlugin.cs @@ -5,29 +5,21 @@ namespace Hosihikari.ScriptManagement; public class LuaPlugin(FileInfo fileInfo) : Plugin(fileInfo) { - private LuaChunk? _luaChunk; + private readonly Lua _lua = new(); protected override void Initialize() { - using Lua lua = new(); - _luaChunk = lua.CompileChunk(_fileInfo.FullName, new()); + // Nothing need to prepare } protected override void Load() { - if (_luaChunk is null) - { - throw new NullReferenceException(); - } - _luaChunk.Run([]); + LuaChunk luaChunk = _lua.CompileChunk(_fileInfo.FullName, new()); + luaChunk.Run([]); } protected override void Unload() { - if (_luaChunk is null) - { - throw new NullReferenceException(); - } - _luaChunk.Lua.Clear(); + _lua.Dispose(); } }