Lua.NET 2.0.3 - How do I cleanly reset Lua's state?

Started by
2 comments, last by AverageJoeSSU 14 years ago
Hi there. I recently started using Lua and C# together thanks to LuaInterface. So far everything works great except for one tiny detail: I'm not able to reset Lua at run-time without generating either an exception or memory leak, and I'm not sure why. I've tried disposing the Lua object itself and re-creating it, and I've tried closing the Lua object and re-creating it. I've even tried just setting it to null and re-creating it, knowing full well that it's going to leak memory but doing it anyway because I ran out of ideas. If someone already knows of a clean way to do this in LuaInterface 2.0.3, please let me know. I'd like to be able to dump the VM and start fresh, rather than trying to clean every single value manually (though I did write a dispose method for handling tables).

GDNet+. It's only $5 a month. You know you want it.

Advertisement
I would download the source from google code and take a look, its actually fairly small.

------------------------------

redwoodpixel.com

I'm looking at the source. Lua.Close() calls lua_close(), and Dispose calls Close() in addition to destroying some other things. There's also an internal (Friend in VB) dispose method that calls lua_unref(), but I don't know where/if this is called. In effect, a call to Dispose should close the VM and free up resources, but when I set Lua to null and try to re-create it, I get .NET errors about protected memory or uninstantiated objects . . . it's not very consistent.

GDNet+. It's only $5 a month. You know you want it.

Interesting, I have stepped down in the code before to debug. if you step down you should be able to figure out exactly what is uninstantiated correct?

I thhhiinnnk i remember reading somewhere that lua interface only uses one lua environment (if this is the case make sure the other one is completely deleted), check for flags and stuff in the constructor that set true, they may not be set to false when the object is deleted.

Also, a link to the dll may be set up for the first Lua object and not for the second.

you should be able to step through the code and see this though.

------------------------------

redwoodpixel.com

This topic is closed to new replies.

Advertisement