From 9b0d029971da9863194ede96a835302564d1e4a7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 30 Aug 2010 11:08:46 -0300 Subject: Add 'luarocks path' command for easy configuration of LUA_PATH and LUA_CPATH --- src/luarocks/build/builtin.lua | 19 +++---------------- src/luarocks/cfg.lua | 17 ++++++++++++++--- src/luarocks/path.lua | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 3473abcb..7c24340e 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -8,19 +8,6 @@ local util = require("luarocks.util") local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") ---- Check if platform was detected --- @param query string: The platform name to check. --- @return boolean: true if LuaRocks is currently running on queried platform. -local function is_platform(query) - assert(type(query) == "string") - - for _, platform in ipairs(cfg.platforms) do - if platform == query then - return true - end - end -end - --- Run a command displaying its execution on standard output. -- @return boolean: true if command succeeds (status code 0), false -- otherwise. @@ -76,7 +63,7 @@ function run(rockspec) end end - if is_platform("mingw32") then + if cfg.is_platform("mingw32") then compile_object = function(object, source, defines, incdirs) local extras = {} add_flags(extras, "-D%s", defines) @@ -105,7 +92,7 @@ function run(rockspec) dir.path(variables.LUA_LIBDIR, "lua5.1.lib"), "-l" .. (variables.MSVCRT or "msvcr80"), "-luser32") return ok, wrapname end - elseif is_platform("win32") then + elseif cfg.is_platform("win32") then compile_object = function(object, source, defines, incdirs) local extras = {} add_flags(extras, "-D%s", defines) @@ -157,7 +144,7 @@ function run(rockspec) local extras = { unpack(objects) } add_flags(extras, "-L%s", libdirs) add_flags(extras, "-l%s", libraries) - if is_platform("cygwin") then + if cfg.is_platform("cygwin") then add_flags(extras, "-l%s", {"lua"}) end return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 8706bd60..261411b7 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -1,6 +1,6 @@ -local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type = - rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type +local rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type, assert = + rawset, next, table, pairs, print, require, io, os, setmetatable, pcall, ipairs, package, type, assert --- Configuration for LuaRocks. -- Tries to load the user's configuration file and @@ -318,7 +318,6 @@ local cfg_mt = { } setmetatable(_M, cfg_mt) - for _,tree in ipairs(rocks_trees) do if type(tree) == "string" then package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path @@ -330,3 +329,15 @@ for _,tree in ipairs(rocks_trees) do end end +--- Check if platform was detected +-- @param query string: The platform name to check. +-- @return boolean: true if LuaRocks is currently running on queried platform. +function is_platform(query) + assert(type(query) == "string") + + for _, platform in ipairs(platforms) do + if platform == query then + return true + end + end +end diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index d07c244e..3ff0db8a 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -7,6 +7,14 @@ module("luarocks.path", package.seeall) local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") +help_summary = "Return the currently configured package path." +help_arguments = "" +help = [[ +Returns the package path currently configured for this installation +of LuaRocks, formatted as shell commands to update LUA_PATH and +LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) +]] + --- Infer rockspec filename from a rock filename. -- @param rock_name string: Pathname of a rock file. -- @return string: Filename of the rockspec, without path. @@ -291,3 +299,17 @@ function versioned_name(file, prefix, name, version) local name_version = (name.."_"..version):gsub("%-", "_"):gsub("%.", "_") return dir.path(prefix, name_version.."-"..rest) end + +--- Driver function for "path" command. +-- @return boolean This function always succeeds. +function run(...) + if cfg.is_platform("unix") then + print("export LUA_PATH='"..package.path.."'") + print("export LUA_CPATH='"..package.cpath.."'") + elseif cfg.is_platform("windows") then + print("SET LUA_PATH="..package.path) + print("SET LUA_CPATH="..package.cpath) + end + return true +end + -- cgit v1.2.3-55-g6feb