Re: Wrapping existing FILE *s as Lua file objects
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Wrapping existing FILE *s as Lua file objects
- From: Mike Pall <mikelu-0701@...>
- Date: 2007年1月15日 03:13:35 +0100
Hi,
Reuben Thomas wrote:
> I have looked at this for a while, and I can't see a way to get rid of the
> GC method without deleting it from the original metatable, which means
> that all files have to be closed manually. Grr. Any other solutions?
Umm, better check liolib.c. The FILE userdatas really need an
environment table with a __close element pointing to a C function
which does the close (or you'll get an exception on GC). Just
make this one a no-op.
Create the environment table once and store it in the environment
of the C function which creates the userdata (look for "popen" at
the end of liolib.c). Userdatas inherit their environment from
the currently active function in the Lua frame stack.
Bye,
Mike