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')
This commit is contained in:
rst256 2015-01-16 05:44:00 +07:00
parent 96a1e6cc6f
commit 805ea9e88d

View File

@ -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.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end}) inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})