[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Problem using posix library pipe() from luajit2?
- From: Sean Conner <sean@...>
- Date: Sun, 27 Mar 2011 14:26:26 -0400
It was thus said that the Great Javier Guerra Giraldez once stated:
> On Sun, Mar 27, 2011 at 6:11 AM, Mike Pall <mikelu-1103@mike.de> wrote:
> >
> > It looks like luaposix copies the internal metatable for files and
> > attaches it to their own userdata object. This doesn't work with
> > LuaJIT. luaposix shouldn't access internals of the VM in this way.
>
> that's unfortunate. i've had to do similar things sometimes, since
> there's no clean way to get to the FILE* from the file object. the
> alternative is not to accept Lua file objects for any C extension that
> uses files.
Perhaps I'm missing something, but I've done stuff like:
Lua:
f = io.open("/tmp/foo","r")
x = blah(f)
C:
int blah(lua_State *L)
{
FILE **pfp;
pfp = luaL_checkudata(L,1,LUA_FILEHANDLE);
/* ... use *pfp to do fileish things */
}
> I guess the best would be to export the tofile() function in liolib.c
> (i'm reading some old sources here, maybe could be there for Lua 5.2?)
LUA_FILEHANDLE is defined in lualib.h so it's not like it's hidden, And
tofile() just masks what I've done above, except it hardcodes the stack
position.
-spc (Unless I'm not supposed to do that ... )