lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 22/10/2013 23:53, Robert Virding wrote:
> 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.

Assigning to "package.loaded[x]" - works (because the table you are
modifying is the same one that really is used to look up package names)

Assigning to "package.loaded", (i.e. attempting to replace the table)
does not work (because there are hidden references to the table, in
the registry and/or upvalues of C functions, and 'require' will
continue to use this table and not the one that you provide.

This is the case in the latest Lua 5.1 and 5.2, LuaJIT 2.0 and 2.1
(though they use different methods to find the table.)


-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJSZwgLAAoJEHp3pOlF38H/qgAIAIK2a1IT7v2yl0m+g4jCzq0q
yincwOgU/3RP5y8WRzCNFnQmOTU2d+FYqcWuBooS4/145k0yaXZB/Cas49AAr6DX
qzvDNKzaM48W0QBmVgwGsKKPMPx5aQDxkNVJh+JuLhntqjCQ9Z0dpBpAMWvCmImT
1zi5NAXm3e7pu7X0AvqPvqyrR0dZFB/7xR4C3deVNxzqbpHPuXGhXoad1afYx3Ru
/6WzGT4srYwqXsn4DObbX1a5HllFlcNFbpiPMBsAyzNwhMZq2HvzSv/kcaOISan5
WUgRFmUuStlhPdl/EWoIPdw8k/HtJL9xisSgDgW2TMEb3APEn+TbM4YkshZL6Xg=
=Yd4m
-----END PGP SIGNATURE-----