lua-users home
lua-l archive

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


Shmuel Zeigerman wrote:
> There is a Lua program that allows users to add their scripts in such a
> way that them will be callable via the program's menu (or via hot keys).
> 
> Every user usually organizes his scripts and modules in a separate
> subdirectory (subtree, in fact) of the main Lua program, and adds this
> subdirectory in front of package.path. This is not elegant, but
> moreover, is not safe, since different users may have identically named
> modules.
> 
> I thought of a solution, where the program assigns each user (that is,
> each group of scripts) a separate environment and calls those scripts
> within that environment. But AFAIK, there is no way to have a
> package.path per an environment, there is only one package.path.
> 
> There is one simple solution: the program modifies package.path every
> time it is about to run a user script. But though it would work, it
> looks inelegant in comparison to imaginary "package.path per environment".
> 
> Are there some other solutions?

There are similar problems in unix-based OSes, and are solved by
environment variables ($HOME, $PATH, etc).

So you can try something like this:

/etc/rc.local:
LUA_INIT=/etc/luaenv.lua

/etc/luaenv.lua:
package.path=os.getenv('HOME')..'/lua;'..package.path
-- or:
-- package.path='/opt/common/lua/'..os.getenv('USER')..';'..package.path

and ask every user to put their modules in their home directories, in
~/lua or /opt/common/lua/<username>.

Regards,
miko