Skip to content

Commit

Permalink
fix: lua engine unloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Yushu2606 committed Aug 19, 2024
1 parent 0f01c19 commit 646c6e8
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/LuaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 646c6e8

Please sign in to comment.