lua-users home
lua-l archive

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


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:

http://www.lua.org/source/5.1/liolib.c.html#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
in luaopen_io().

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
else.

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 ...

    -Mark


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