lua-users home
lua-l archive

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


Hi,

> For the sake of exactness, should the require() function in compat-5.1
> remove items from package.preload once they have been promoted to
> package.loaded status?

It is strange that two people would notice this. Is there any reason why
keeping the function in package.preload would be harmful? The only
problem I see is memory consumption because of a strong reference that
might prevent the collector from getting rid of it (and whatever it
references).

For situations where this is an issue, the loader function itself could
remove the reference.

> Whilst this doesn't matter, given the way require() is implemented, it
> seems wrong that a library that is already loaded should still have its
> initialisation function in the "preload" table. Or is it envisaged that
> packages might get unloaded and reloaded later, or that they might
> get loaded more than once?

Seems to me like keeping the package.preload is the only way you can get
a fresh copy of a namespace table in a static setting. Cloning doesn't
work in some cases. Getting fresh copies of a namespace might be useful
for sandboxing purposes.

Then again, whenever this is important, the behavior could be reverted
back to the original.

In summary, it really doesn't seem to matter. :)

[]s,
Diego.