lua-users home
lua-l archive

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


On Fri, Aug 31, 2012 at 12:50 PM, Seppl Vorderhörer <Seppl.Vorderhoerer@t-online.de> wrote:
Hello,

I'm using Lua 5.2 directly embedded in another program (compiled as C++ code).

When using "require(SomePath)" inside scripts I saw, that require (beside a lot of other things) also does a replacement inside SomePath of "." with the directory separator ("\" in my use case, as I'm using windows).

After some digging in the manuals and the code I found out, that this substitution is not configurable for the standard lua Searcher used. Both the standard Lua and C searchers (functions searcher_C and searcher_Lua) use the internal function findfile which itself uses searchpath() but unfortunately with a hardcoded "." as separator.

For this I have two questions:
1.) Why is this behaviour hardcoded? Shouldn't there be some configuration possibility like for the other special characters used e.g. in package.config?

2.) Is it a good idea to use a special character that has another meaning on some (or basically most) file systems in existence? "." and ".." are used for "current" or "parent directory" under Windows.

3.) What is the point of this replacement when looking for a filename as done in findfile() anyway? Actually I don't see the reason, why this is done at all and I have the feeling, that I miss something here.

Background:
What I try to achieve is to make require work with relative pathnames, especially with being able to reach parent directories of certain scripts.
I checked the mailing lists and found already some discussions about that but nothing describing the issue above.

What I see is that if I try something like

    require("..\\OtherDir\\OtherFile.lua")

this fails due to the fact that the internally used function findfile() replaces the dots by directory separators.
A simple patch not replacing the "." and voi'la I can use relative paths containing "." or ".." without any problem.

Is there a reason behind this behaviour and is there maybe a possibility to achive the same without patching the original Lua source files?

Greetings,
Seppl


I believe the problem is that, conceptually, require was thought to be used with a _module name_, not a path.

On PIL 5.1 the illustrated code for require strongly suggests that.

This ability to replace '.' for path separators is probably there to imitate the behavior of java packages.

While 'programming in the large' with lua, I find this very useful.

I understand that one could make use of more flexible mechanisms for searching modules, but I believe they belong on package.path, not on the module names.

Gasho.
--
Luís Eduardo Jason Santos