lua-users home
lua-l archive

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

DarkGod <> wrote:
> Now when I do that(see code below) it works all fine except when one of 
> my file handles needs to
> be garbage collected I get a nasty segfault.
> But if I put my code into lua's liolib.c (registering it in luaL_Reg 
> iolib[]) and compile it, it works just fine.
> The crash happens in liolib.c:aux_close():120, seemingly missing the 
> "__close" field.
> I'm creating my handle the same way iolib does, assigning the metatable, 
> so there must be something very
> basic and stupid I'm forgetting right?

Try this snippet (you'll probably have to adapt it, as it's verbatim
from one of my libraries):

void initIO(lua_State * L) {

Basically you have to connect the handles created by a pipe call with
the correct close() function... and that is what the code above does: it
takes stderr's environment and copies that to pipe()'s.

(My  C function that creates the pipes is unsurprisingly called pipe()).

cheers  thomasl

web :