[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re-requiring modules
- From: Robert Virding <robert.virding@...>
- Date: Wed, 23 Oct 2013 00:53:21 +0200 (CEST)
Yes, BUT NO. Well it shouldn't work. In the 5.2 manual description of package.loaded it says
"package.loaded
A table used by require to control which modules are already loaded. When you require a module modname and package.loaded[modname] is not false, require simply returns the value stored there.
This variable is only a reference to the real table; assignments to this variable do not change the table used by require."
Which seems to imply that these suggestions should not work. This is why I was asking as otherwise it is easy.
Robert
----- Original Message -----
> From: "Luiz Henrique de Figueiredo" <lhf@tecgraf.puc-rio.br>
>
> > Is it possible to re-require a module?
>
> function rerequire(m)
> package.loaded[m] = nil
> return require(m)
> end
>
> or if your module sets a global:
>
> function rerequire(m)
> package.loaded[m] = nil
> _G[m] = nil
> _G[m] = require(m)
> return _G[m]
> end
>
> Search lua-l archive for unrequire. See for instance
> http://lua-users.org/lists/lua-l/2012-12/msg00883.html
>
>