From 67a7d4faee164903769d001abbebd1073ad87e01 Mon Sep 17 00:00:00 2001 From: Hisham Date: Thu, 6 Oct 2016 11:51:31 -0300 Subject: Make the workaround for older LuaRocks versions more robust. --- src/luarocks/loader.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 06a0cfda..874bc10c 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -23,8 +23,25 @@ local deps = require("luarocks.deps") local util = require("luarocks.util") -- Workaround for wrappers produced by older versions of LuaRocks +local temporary_global = false if luarocks then + -- The site_config.lua file generated by old versions uses module(), + -- so it produces a global `luarocks` table. Since we have the table, + -- add the `loader` field to make the old wrappers happy. luarocks.loader = loader +else + -- When a new version is installed on top of an old version, + -- site_config.lua may be replaced, and then it no longer creates + -- a global. + -- Detect when being called via -lluarocks.loader; this is + -- most likely a wrapper. + local info = debug.getinfo(2, "nS") + if info.what == "C" and not info.name then + luarocks = { loader = loader } + temporary_global = true + -- For the other half of this hack, + -- see the next use of `temporary_global` below. + end end loader.context = {} @@ -60,6 +77,13 @@ function loader.add_context(name, version) -- assert(type(name) == "string") -- assert(type(version) == "string") + if temporary_global then + -- The first thing a wrapper does is to call add_context. + -- From here on, it's safe to clean the global environment. + luarocks = nil + temporary_global = false + end + if loader.context[name] then return end -- cgit v1.2.3-55-g6feb