[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why the dot in package.path? ..and finding the source filename
- From: David Manura <dm.lua@...>
- Date: Wed, 8 Jul 2009 21:41:37 -0400
On Wed, Jul 8, 2009 at 1:53 PM, Petite Abeille wrote:
> On Jul 8, 2009, at 3:11 PM, steve donovan wrote:
>> It would be IMHO rather more useful to have something meaning
>> 'directory of current module'...
>
> I would second that... it would indeed be rather handy for modules to
> seamlessly know where they where loaded from...
The mapping of module names to file paths is contained inside
package.path and package.cpath. You can parse this information
yourself--for example, see [1].
That assumes package.path/cpath and the current directory don't change
in an incompatible way between when a module is loaded and when you
query the path information again. If this is any concern (and I
suppose it is not), you may redefine require to immediately compute
and store the module path when a module is loaded.
[1] http://lua-users.org/lists/lua-l/2008-11/msg00308.html