lua-users home
lua-l archive

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


On Tue, Oct 18, 2011 at 11:05 AM, Julien Duminil
<julien.duminil@ubisoft.com> wrote:
> require stores "modules" that have already been required in package.loaded[modname] so that if you load the same module twice, it loads it only once:

Yes, it's a brilliant feature that we take for granted.  (dofile()
will do exactly what you tell it to do)

$> lua -lpl.utils
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> = package.loaded['pl.utils']
table: 0036BCC0

(as an aside, if you change a module and want to reload inside a
session, then package.loaded['mod'] is what you need to zap to nil to
actually get a re-load.)

Penlight uses some serious voodoo to prevent excessive code loading.
require 'pl' appears to be a kitchen-sink include, but the modules
(such as lapp, tablex, etc) are only loaded on first use.  Of course,
module writers and generally careful people don't just say require
'pl' ;)

steve d.