lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Reuben Thomas wrote:
On Sun, 14 Jan 2007 07:27:42 -0000, Mark Edgar <medgar@student.gc.maricopa.edu> wrote:

     FILE **pf = lua_newuserdata(L, sizeof *pf);
     *pf = 0;
     luaL_getmetatable(L, LUA_FILEHANDLE);
     lua_setmetatable(L, -2);
     *pf = /* your FILE* here */

Why is *pf initially set to NULL?

If there is any error after allocation, the __gc metamethod in liolib.c won't call fclose() on an uninitialized FILE* value.

					-Mark