lua-users home
lua-l archive

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


It works. Thank you.


On Fri, May 23, 2014 at 6:38 AM, Duncan Cross <duncan.cross@gmail.com> wrote:
On Fri, May 23, 2014 at 11:25 AM, Minh Ngo <mkngo87@gmail.com> wrote:
> Is there an easy way to do the following without making a global variable?

You could explicitly set package.loaded[current_module_name] in each
module script, before ever calling require():

> @/foo.lua
> local foo = {}
package.loaded["foo"] = foo
> foo.bar = require("foo.bar")
> return foo
>
> @/foo/bar/init.lua
> local bar = {}
package.loaded["foo.bar"] = bar
bar.foo = require("foo")
> return bar

...it's a bit messy and you do have to be a bit more careful in the
main body of each of these scripts (since the require'd modules will
just be empty tables at the time of execution) but it should work.

-Duncan




--
Minh Ngo