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 <> wrote:
> Hisham <> wrote:
>> But having to write "" (or "", or ""...) 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
  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.