[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Thu, 28 Jan 2010 11:44:26 +0100
2010/1/28 Alexander Gladysh <agladysh@gmail.com>:
>>> require "bit"
>
>>> What are the pros and cons of doing this?
>
>> What if a person explicitly wanted LuaBitOps, which also has a module
>> name 'bit'?
>
> Exactly.
>
> It looks like we would be using Mike's library for a while, so we do
> not have to overhaul whole existing codebase due to the changed
> semantics.
The exact same problem applies for the io library, what if someone
wants to replace it with a custom one (for example that yields on
blocking calls) ?
One partial solution is to "unload" the module, that is remove the
global, remove the entry in package.loaded, and eventually remove the
entry in package.preload (so that the old module don't get loaded
again). AFAICT standard modules are not in package.preload though.
However it's only partial, because any existing reference to the old
module won't be updated (and it's too often considered a good habit to
cache access to modules in locals).
The real solution is to have a custom interpreter that doesn't preload
modules. I once proposed to add the support for a -l- option that
would prevent loading standard libraries (I mean everything except _G
and package). I have a patch for 5.1 if someone wants to have a look.