lua-users home
lua-l archive

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

On Tue, Oct 5, 2010 at 2:16 PM, steve donovan <> wrote:
On Tue, Oct 5, 2010 at 1:56 PM, Thijs Koerselman
<> wrote:
> local require, print = require, print
> module 'mymodule'
> require 'string'
> print(string.format('%s', 'some string'))

After your call to module(), the environment of the chunk has changed,
and require 'string' isn't clever enough to bring the name 'string'
into the module environment. You would have to say 'local string =
require 'string'' at this point.

This is the kind of weirdness that has led to Lua 5.2 dropping
module() altogether - too much messing around with function

Thanks Steve, I get it. I see that both module and setenv are deprecated in 5.2. What is the most basic way to create a module with

- no pollution of global namespace
- no prefix required for methods to call each other inside module.
- no deprecated functions

I only know how to do this with setenv, and I'm not sure how to replace it with _ENV