lua-users home
lua-l archive

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


On Monday, October 07, 2013 03:15:15 PM Andre Arpin wrote:
> This is verbatim from the wiki.
> 
> (function()
>   local require = require
>   local print = print
>   local module = module
>   module("yourmodule");
> 
>   (function() module("mymodule") end)()
> 
>   print(mymodule ~= nil) -- prints false (where is it?)
> end)();

This led me to discover something interesting.

    (function()
      local print = print
      local module = module

      module("yourmodule")
    
      print(module) -- function: 0x108f960

      (function()
        module("mymodule")
      end)()
    
      print(module) -- table: 0x10b0470
    end)()

The module function is mutating the first upvalue of the calling function 
without regard to whether it is the _ENV table.

-- 
tom <telliamed@whoopdedo.org>