Closed rst256 closed 9 years ago
Hi there,
I am sorry, but I will have to reject this PR. The problem with the example is that a global variable has been redefined; once this is done, all bets are off. You could redefine require
and not be able to even include inspect
in the first place.
require = {}
local inspect = require 'inspect' -- same error: attempt to call a table value (global 'require')
Even with your solution, if fn(1,2,3)
is executed before requiring, you will have the same problem:
function fn(...) setmetatable = {...} return setmetatable end
fn(1,2,3)
require 'inspect'
-- attempt to call a table value (global 'setmetatable')
Since it is impossible to fix this problem completely, I prefer to go the other way around: not fix it at all, so it is obvious that there's a problem.
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')