lua-users home
lua-l archive

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


Hi,

The function module() simply makes your global table be your own module
table. This has the effect of ensuring all globals you define will end
up in your namespace. It has the side-effect of preventing you from
accessing global variables as soon as you call module(). But check
package.seeall.

local string = string
module "a"

I usually do

    local string = require"string"
    module"a"
    ...

but this is rather ugly, especially for functions in the top level, which I then have to treat one at a time:

local require, print = require, print

I usually do

    local base = _G
    base.print("Hello world!")

Also, what if I want to use functions from a module required by the current one, e.g.

local require = require
module "a"
require "b"
b.foo()

Does module "b" depend on "a"? If not, then

    local b = require"b"
    module "a"
    b.foo()

Regards,
Diego.