On 26 Jun 2013, at 00:07, Hisham <h...@hisham.hm> wrote: > On 25 June 2013 11:27, Gary V. Vaughan <g...@vaughan.pe> wrote: >> Hi Hisham, >> >> I'm having trouble developing the next version of my Lua packages >> while the previous (stable) release are installed as rocks... and >> where both stable (installed) and development (in working dir) >> need access to the rocks tree for the packages they in turn depend >> on. >> >> Let's say I run bin/specl from my dev tree, which contains: >> >> require 'specl.util' >> >> I want that link to pick up the dev version of that file from >> lib/specl/util.lua (in the dev tree), but when I run: >> >> LUA_PATH='./lib/?.lua;;' bin/specl >> >> ...the require function actually loads the (incompatible) stable >> version from the rocks tree, in /usr/local/share/lua/5.2/specl/util.lua, >> because luarocks has pushed my LUA_PATH setting too far down the >> package.path IMHO: >> >> $ LUA_PATH='./lib/?.lua;;' lua5.2 /usr/local/bin/luarocks path >> >> export LUA_PATH='/usr/local/share/lua/5.2/?.lua;\ <<< loads from here >> /usr/local/share/lua/5.2/?/init.lua;\ >> /Users/gary/.luarocks/share/lua/5.2/?.lua;\ >> /Users/gary/.luarocks/share/lua/5.2/?/init.lua;\ >> /usr/local/luarocks/HEAD/share/lua/5.2//?.lua;\ >> /usr/local/luarocks/2.0.12/share/lua/5.2//?/init.lua;\ >> ./lib/?.lua;\ <<< instead of here >> /usr/local/lib/lua/5.2/?.lua; >> /usr/local/lib/lua/5.2/?/init.lua; >> ./?.lua;' >> >> (indented for clarity) >> >> I think luarocks should add it's additional directories just before the >> system path, marked by ;; in my LUA_PATH setting. Have I installed >> luarocks incorrectly? Or is there another way to add my working tree >> paths to the *front* of LUA_PATH? >> >> If not, then it seems like `luarocks path` is broken :( > > Well, the point of `luarocks path` _is_ to ensure that the > LuaRocks-installed modules are found. I see no other way of doing > that. > > Is your bin/specl script resetting the package.path?
Not directly, but I'm following the recipe at http://lua-users.org/wiki/LuaRocksConfig to manage parallel rocks trees for 5.1, 5.2 and luajit, so when the OS sees #!/usr/bin/env lua (or I call bin/specl with `luajit bin/specl`) it actually runs a wrapper script which then runs `luarocks path` to make the right rocks tree visible... but unfortunately, also pushing any user LUA_PATH settings from the environment too far down the package.path to be useful :( > I would expect > something like this to work to your liking: > > $ luarocks path > export LUA_PATH="/paths/set/by/luarocks/..." > $ eval `luarocks path` > $ echo $LUA_PATH > /paths/set/by/luarocks/... > $ LUA_PATH="./lib/?.lua;$LUA_PATH" lua -e 'print(package.path)' > ./lib/?.lua;/paths/set/by/luarocks/... > $ LUA_PATH="./lib/?.lua;$LUA_PATH" bin/specl > # works as intended?... > > Am I missing something? Not at all, I oversimplified my explanation. Even so, I still think appending luarocks directories rather than prepending is a much more useful behaviour to work with. Otherwise, I need to change my wrapper scripts to save and clear LUA_PATH and LUA_CPATH before calling "eval `luarocks path`" and then then afterwards push the saved values back onto the front of LUA_PATH and LUA_CPATH as returned by luarocks? e.g. change the lua5.1 wrapper from the wiki recipe to: #!/bin/sh PATH=/usr/local/opt/lua/bin:/usr/local/opt/luarocks/bin:$PATH LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.1.lua export LUAROCKS_CONFIG save_LUA_PATH=$LUA_PATH save_LUA_CPATH=$LUA_CPATH LUA_PATH= LUA_CPATH= eval `luarocks path` test -n "$save_LUA_PATH" && LUA_PATH=$save_LUA_PATH;$LUA_PATH test -n "$save_LUA_CPATH" && LUA_CPATH=$save_LUA_CPATH;$LUA_CPATH exec lua ${1+"$@"} That still seems like something that "luarocks path" itself could handle better, and more transparently. Less obvious, but arguably more useful, then, would be to for luarocks path to simply ignore LUA_PATH and LUA_CPATH from the environment, and output purely the paths needed for luarocks itself, which would make assembling a full path from a wrapper script much less fiddly: #!/bin/sh : {LUA_PATH=";"} : {LUA_CPATH=";"} export LUA_PATH export LUA_CPATH PATH=/usr/local/opt/lua/bin:/usr/local/opt/luarocks/bin:$PATH LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.1.lua LUA_PATH=$LUA_PATH;`luarocks path` LUA_CPATH=$LUA_CPATH;`luarocks cpath` exec lua ${1+"$@"} At a slight tangent, 'export foo=bar' is not as portable as 'export foo; foo=bar' which works in pure Bourne shells (on machines that don't just link it to bash). Cheers, -- Gary V. Vaughan (gary AT vaughan DOT pe) ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Luarocks-developers mailing list Luarocks-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/luarocks-developers