|
On Fri, May 23, 2014 at 11:25 AM, Minh Ngo <mkngo87@gmail.com> wrote:You could explicitly set package.loaded[current_module_name] in each
> Is there an easy way to do the following without making a global variable?
module script, before ever calling require():
> @/foo.lua
> local foo = {}
package.loaded["foo"] = foo
> foo.bar = require("foo.bar")package.loaded["foo.bar"] = bar
> return foo
>
> @/foo/bar/init.lua
> local 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