Use __metatable to give them a table that is actually not a metatheme, or to give the library another setmetatable method: that way they cannot change your _G meta tags.
getmetatable(getfenv()).__metatable = function ( o ) return { } end
OR
local orig_setmetatable = setmetatable function setmetatable ( ob , mt ) if ob == getfenv() or ob == _G then return ob else return orig_setmetatable(ob,mt) end end
(depending on how the library does something)
If you still want to track what it does with the metathema; look at mt before returning ob (and if you really want to link the __index search add to the table):
local env_indexes = {} setmetatable(_G,{__index=function(t,k) for i,m in ipairs(env_indexes) do local v=m[k]; if v then return v end end return nil end } ) local orig_setmetatable = setmetatable function setmetatable ( ob , mt ) if ob == _G then table.insert ( env_indexes , mt.__index ) return ob else return orig_setmetatable(ob,mt) end end
Otherwise, this is a very bad practice for libraries; tell the author not!
source share