lua-users home
lua-l archive

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


Assume I have two modules, banana.lua and mango.lua, implemented in 
separate files which I require() separately. Assume that each module 
starts with a line like this:

  module(...,package.seeall)

If I simply concatenate the two files into, say, fruit.lua, and change the 
module() specifiers so they are like this:

  module('banana',package.seeall)
  -- rest of banana.lua

  module('mango'),package.seeall)
  --rest of mango.lua

will I get identical results from "require(fruit)" as I used to get 
from "require('banana'); require('mango')"?

And if so, is there a way of "escaping" from the most recent call 
to module(), for example so that I could concatenate my main program onto 
the end of fruit.lua to make a single file with all by require() 
dependencies fulfilled inside?

Is it sufficient to prepend:

  orig = getfenv(1)

before the first module code and to append:

  setfenv(orig)

afterwards?