lua-users home
lua-l archive

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


> Is there a clean way of creating new handles that'll work with the other
> functions in the io library, such that one could write an extension and
> put it in such a library?

Yes.


> If so, where is it documented?

Right here :) You must create a userdata containing only the FILE* and
set its metatable to the value at REGISTRY["FILE*"]:

  FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
  *pf = popen or whatever...
  luaL_getmetatable(L, LUA_FILEHANDLE);
  lua_setmetatable(L, -2);


> 'popen' is closed the same was as regular 'open'...

Yes, that's true. We will have to solve that problem... 


> What's wrong with just having another flag in the userdata to say it's
> a popen,

That needs special support from iolib. Even if we agree to put popen
back there, we still have the problem for other external file handles
(e.g., pipes).

-- Roberto