From 805ea9e88db9011522f33e1e57e173b307ae3005 Mon Sep 17 00:00:00 2001 From: rst256 Date: Fri, 16 Jan 2015 05:44:00 +0700 Subject: [PATCH] Store used external function in local scope Fix bug like this: function fn(...) setmetatable = {...} return setmetatable end print(inspect(fn(1,2,3))) -- error, attempt to call a table value (global 'setmetatable') --- inspect.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/inspect.lua b/inspect.lua index b7107d4..b9d1d56 100644 --- a/inspect.lua +++ b/inspect.lua @@ -28,6 +28,17 @@ local inspect ={ ]] } +local pairs = pairs +local ipairs = ipairs +local type = type +local math = math +local tostring = tostring +local rawset = rawset +local next = next +local getmetatable = getmetatable +local table = table +local setmetatable = setmetatable + inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end}) inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})