[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua VM Exception Handling
- From: Matt Campbell <mattc@...>
- Date: Sat, 01 Jul 2006 10:20:05 -0500
Hello Andrew:
The correct solution is to wrap the library-allocated data in a
userdatum whose __gc metamethod frees the data. This way, the data is
under the control of the Lua garbage collector. Then you no longer have
to explicitly free it at the end of your C function; just make sure the
userdatum stays on the Lua stack. And you'll know that the data will
always eventually be freed when it's no longer needed, even if a Lua
error occurred. For more information, see the chapter on managing
resources in the book _Programming in Lua_, the first edition of which
is available at no charge online.
--
Matt Campbell
Lead Programmer
Serotek Corporation
www.freedombox.info
"The Accessibility Anywhere People"