[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Replacement for luaL_openlib in Lua 5.1
- From: Rici Lake <lua@...>
- Date: Sat, 3 Dec 2005 00:00:35 -0500
On 2-Dec-05, at 9:46 PM, David Burgess wrote:
On 12/3/05, Rici Lake <firstname.lastname@example.org> wrote:
This can be done, as it is in loadlib.c and liolib.c. It requires that
C function that is doing the lua_replace has its own lua stack (i.e.
As far as I know, lua_replace will not work with the LUA_ENVIRONINDEX
Right you are; there is a special check in lua_replace for that very
case. So I take it back, you can set your own environment with
I do not understand why.
The io library uses an environment table for data shared between the
various io methods: specifically, the current input and output file
descriptors. I imagine that the package system has a similar need.
The 5.0.2 io library uses the "FILE" metatable for this purpose, but
that makes the data non-private:
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
> f = io.open"/dev/null"
--> contrast (note that the fenv wouldn't be visible without the debug
library, which is one of the reasons you shouldn't include the debug
library in production builds)
Lua 5.1 (beta) Copyright (C) 1994-2005 Lua.org, PUC-Rio
> for k, v in pairs(debug.getfenv(io.read)) do print(k,v) end
1 file (0x281eaf00)
2 file (0x281eaf58)
__close function: 0x8082900