0

The Lua script is over, but the C# class instantiated in the lua script has not been released, it is still running, how do I release the corresponding resources?

I want to call C# resources through Lua scripts, and when Lua scripts stop, release all called C# resources at the same time. When you run the script again, reload the appropriate resources

The main code is as follows

 using (Lua state = new Lua())
{
    state.RegisterLuaDelegateType(typeof(TestDelegate), typeof(LuaClass));
    state.DoString("luanet.load_assembly('LuaTest','LuaTest.SomeClass')");
    state.DoString("TestClass=luanet.import_type('LuaTest.SomeClass')");
    state.DebugHook += State_DebugHook;
    void State_DebugHook(object? sender, NLua.Event.DebugHookEventArgs e)
    {
        Console.WriteLine(e.LuaDebug);
    }
    state.LoadCLRPackage();
    state.DoString(@"test=TestClass()
        test.testDelegate=function(a,b)
          print(a+b)
          return a+b;
         end
");  
}
Console.ReadLine();






public class SomeClass
{
     private System.Timers.Timer t;
        public TestDelegate testHandler;
        public SomeClass()
        {
          
            t = new System.Timers.Timer(1000);
            t.AutoReset = true;
            t.Enabled = true;
            t.Elapsed += T_Elapsed;
            t.Start();
        }

        private void T_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
        {
            if (testHandler != null)
            {

                testHandler(1,2);
            }
        }
}
Nifim
  • 4,758
  • 2
  • 12
  • 31
ambit
  • 1

0 Answers0