[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Recommended way to get file directory
- From: "J.Jørgen von Bargen" <jjvb.primus@...>
- Date: Thu, 24 Feb 2011 14:04:56 +0100
The problem lies in nested scripts that do not (and should not) know
the absolute position of the required sub-scripts (relative to "/" or
to the running application).
I have a similar problem with loading libraries for our testing system.
The layout is about this (well, with lot's more of files)
in testlib/path.lua I simply have
(because the way module/require works, this will only be executed once,
no matter how often require"testlib.path" is used)
I a testenvironment I copy the testlib into a subfolder (well, really I
check it out from a subversion repository, but that does not matter
here, and there are *many* testenvironments, which share the testlib in
So it looks like this
The testcases then look like this
require"testlib.path" -- get path to the testlib
require"communication.client" -- load the client
-- connect to device
-- call some functions
This works nearly fine but one problem remains:
In communication/client.lua I do a require"communication.jxml", which is
ok when called from testcaseX, because the path is set accordingly.
But when I want use the client.lua and jxml.lua somewhere else, the
require will fail, so I have to do
package.path=package.path..";../?.lua" in the client.lua to get it
working, which doesnt make me happy.
On the other hand, when I do require"jxml", the client will work
standalone, but will not be usable in the testlib, because the require
then will fail.
Any suggestions to solve this better?