[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Require / lua-searchers / findfile: Why is the dot replaced by the dir separator?
- From: Seppl Vorderhörer <Seppl.Vorderhoerer@...>
- Date: Fri, 31 Aug 2012 17:50:11 +0200
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