[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: from: Lua Module Function Critiqued
- From: Andrew Starks <andrew.starks@...>
- Date: Tue, 8 Oct 2013 20:14:51 -0500
On Tuesday, October 8, 2013, Tom N Harris wrote:
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>
In lua 5.2, my understanding is that _ENV is always the first upvalue. Is this not true?
-Andrew