[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Polymorphic luaL_checkudata?
- From: Peter Odding <xolox@...>
- Date: Mon, 16 Apr 2007 04:47:29 +0200
Mark Edgar wrote:
I suppose I could be more specific and more helpful:
liolib.c needs to call pclose() instead of fclose() when the
file:close() metamethod is called. This is handled by aux_close:
The __close field is stored in the environment of each popen'ed
userdatum. This is done automatically because popen'ed userdata are
created only in io_popen() whose environment table is set explicitly
Similarly, you could set an environment table on your function which
creates pipe userdata. Your get/set_timeout metamethods could use the
presense of this environment table (or a certain field contained in
it) to determine if a given userdata is indeed a pipe or something
Note that if you want APR pipes to have the same semantics as
io.popen'ed pipes, then most of this work is already done for you ...
Thanks for your detailed explanation. Note that I already have liolib.c opened
next to apr/src/io_file.c permanently because I'm making the interface
compatible with Lua's io library and liolib.c is a valuable source of inspiration.
You don't think it's bad style to add (get|set)_timeout to the file userdata
methods? Not trying to criticize, just interested in your opinion.
For now I've decided to use a different metatable + __index for pipes, which
means the (get|set)_timeout methods are only available on pipe userdata. This
also means all argument validation in the file/pipe io library needs the
luaL_checkudata_ex() helper I posted earlier in this thread. I'm not yet sure
whether I prefer this or your suggestion above.
Thanks again to everyone for their input!
- Peter Odding