lua-users home
lua-l archive

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


Mike Pall wrote:

Hi,

Chris Marrin wrote:

I see in 5.1-work6 that you can now set environments not only on both C and Lua functions, but also on userdatas. But I don't see anywhere in the code where this environment is being used. What can you do with this environment? Does it get used when you make metamethod calls with this userdata? Or is it just there so it can be retrieved or something?


http://lua-users.org/lists/lua-l/2005-04/msg00213.html

Thanks for the pointer. This brings up a question:

- I assume that luaopen_queue() is what gets implicitly called when you do the require "queue", right? If so, then it looks like it sets the environment for your test program to the environment for the queue, as evidenced by lua_replace(L, LUA_ENVIRONINDEX). Looking at the code for this, it gets the current function (which is the main lua program at this point?) and sets its environment to the passed table(which is the metatable you are constructing for queue). Doesn't that change the environment for the whole program?

Thanks for your help...

--
chris marrin              ,""$, "As a general rule,don't solve puzzles
chris@marrin.com        b`    $  that open portals to Hell" ,,.
        ,.`           ,b`    ,`                            , 1$'
     ,|`             mP    ,`                              :$$'     ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`