[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules, require, magic
- From: David Manura <dm.lua@...>
- Date: Fri, 21 Oct 2011 00:12:24 -0400
On Wed, Oct 19, 2011 at 12:52 PM, Tony Finch <dot@dotat.at> wrote:
> Hisham <hisham.hm@gmail.com> wrote:
>> But having to write "module.bar" (or "M.bar", or "_M.bar"...) in every
>> use of module functions within the module is cumbersome.
> Muddling up the global and module namespaces is not clean.
Returning to an example based on what I posted before [1]:
_ENV = module(...)
local tostring = tostring
local baz = require "baz"
.....
local test
function foo(...) ..... end
Bar = class('Bar', function(_ENV)
.....
function tostring(self) -- NOTE! actually defines a local function
return foo(self.x) -- NOTE! does not necessarily access foo
in parent _ENV scope
end
end)
function test() ..... end -- NOTE! this is a forward declared local
(but resembles a global)
Here we attempt _ENV tricks for both modules and classes, and I'm
skeptical that the scoping meshes well.
[1] http://lua-users.org/lists/lua-l/2010-07/msg00224.html
- References:
- modules, require, magic, Eduardo Ochs
- Re: modules, require, magic, Javier Guerra Giraldez
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Sam Roberts
- Re: modules, require, magic, David Manura
- Re: modules, require, magic, Hisham
- Re: modules, require, magic, Tony Finch
- Re: modules, require, magic, Hisham
- Re: modules, require, magic, Tony Finch