aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-10-06 11:51:31 -0300
committerHisham <hisham@gobolinux.org>2016-10-06 11:51:31 -0300
commit67a7d4faee164903769d001abbebd1073ad87e01 (patch)
treea0286bed898166a47987065c0396ef656cf0c638 /src
parent5f3b2b79bbba5de0a571188c08b42a213aac772f (diff)
downloadluarocks-67a7d4faee164903769d001abbebd1073ad87e01.tar.gz
luarocks-67a7d4faee164903769d001abbebd1073ad87e01.tar.bz2
luarocks-67a7d4faee164903769d001abbebd1073ad87e01.zip
Make the workaround for older LuaRocks versions more robust.
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/loader.lua24
1 files changed, 24 insertions, 0 deletions
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")
23local util = require("luarocks.util") 23local util = require("luarocks.util")
24 24
25-- Workaround for wrappers produced by older versions of LuaRocks 25-- Workaround for wrappers produced by older versions of LuaRocks
26local temporary_global = false
26if luarocks then 27if luarocks then
28 -- The site_config.lua file generated by old versions uses module(),
29 -- so it produces a global `luarocks` table. Since we have the table,
30 -- add the `loader` field to make the old wrappers happy.
27 luarocks.loader = loader 31 luarocks.loader = loader
32else
33 -- When a new version is installed on top of an old version,
34 -- site_config.lua may be replaced, and then it no longer creates
35 -- a global.
36 -- Detect when being called via -lluarocks.loader; this is
37 -- most likely a wrapper.
38 local info = debug.getinfo(2, "nS")
39 if info.what == "C" and not info.name then
40 luarocks = { loader = loader }
41 temporary_global = true
42 -- For the other half of this hack,
43 -- see the next use of `temporary_global` below.
44 end
28end 45end
29 46
30loader.context = {} 47loader.context = {}
@@ -60,6 +77,13 @@ function loader.add_context(name, version)
60 -- assert(type(name) == "string") 77 -- assert(type(name) == "string")
61 -- assert(type(version) == "string") 78 -- assert(type(version) == "string")
62 79
80 if temporary_global then
81 -- The first thing a wrapper does is to call add_context.
82 -- From here on, it's safe to clean the global environment.
83 luarocks = nil
84 temporary_global = false
85 end
86
63 if loader.context[name] then 87 if loader.context[name] then
64 return 88 return
65 end 89 end