From 9134a9986e1714f532cc07c8646c39ffcd522bc6 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 29 Dec 2014 20:45:12 +0000 Subject: Remove setfenv call from mvc.lua for Lua 5.2 compatibility --- lua/mvc.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'lua') diff --git a/lua/mvc.lua b/lua/mvc.lua index ea1037e..174766c 100755 --- a/lua/mvc.lua +++ b/lua/mvc.lua @@ -273,13 +273,19 @@ mymodule.read_config = function( self, appname, home ) self.conf.app_hooks = {} setmetatable (self.conf.app_hooks, {__index = _G}) - -- loadfile loads into the global environment - -- so we set env 0, not env 1 - setfenv (0, self.conf.app_hooks) - local f = loadfile(self.conf.confdir .. "/" .. appname.. "-hooks.lua") - if (f) then f() end - setfenv (0, _G) - -- setmetatable (self.conf.app_hooks, {}) + local IS_52_LOAD = pcall(load, '') + if IS_52_LOAD then + local f = loadfile(self.conf.confdir .. "/" .. appname.. "-hooks.lua", "bt", self.conf.app_hooks) + if (f) then f() end + else + -- loadfile loads into the global environment + -- so we set env 0, not env 1 + setfenv (0, self.conf.app_hooks) + local f = loadfile(self.conf.confdir .. "/" .. appname.. "-hooks.lua") + if (f) then f() end + setfenv (0, _G) + -- setmetatable (self.conf.app_hooks, {}) + end end end -- cgit v1.2.3