lua-users home
lua-l archive

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


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