From 34963cbc145f9ea1521c24919a9c2c38ee24a7d8 Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 5 Oct 2016 03:18:26 -0300 Subject: Simulate module() for older wrappers. Older versions of LuaRocks (e.g. 2.1.0) install script wrappers that assume that `luarocks.loader` is available in the global namespace (this is from the module() era). This workaround detects this (because site_config.lua files written by these old versions use module(), and therefore create a `luarocks` global. To reproduce this issue, make a clean install of LuaRocks 2.1.0, then run `luarocks install luarocks`. Installation succeds, but running `luarocks` produces `attempt to index field 'loader' (a nil value)`. Bug reported by @tomasguisasola. --- src/luarocks/loader.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 26280e94..06a0cfda 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -22,6 +22,11 @@ local manif_core = require("luarocks.manif_core") local deps = require("luarocks.deps") local util = require("luarocks.util") +-- Workaround for wrappers produced by older versions of LuaRocks +if luarocks then + luarocks.loader = loader +end + loader.context = {} -- Contains a table when rocks trees are loaded, -- cgit v1.2.3-55-g6feb