Reputation: 71
I was wondering if there is any way to escape the __metatable metamethod. I know there isn't one, but I'm trying to do something like this, but obviously __metatable blocks that from happening:
-- pretend that there is a __metatable field given to a table
setmetatable(_G, {__index = {None="No indexes"}})
-- error: (the string given to the __metatable metamethod)
What I am trying to do here is simply escape past the __metatable field and simply allow myself to set a metatable on _G, which already has one. I know it is impossible to do this, but I'd like to ask if there is still a chance to bypass?
Upvotes: 4
Views: 2010
Reputation: 1
I would just override the metables.
You can do that by using synapse x overridemetables()
.
Upvotes: -3
Reputation: 72402
The only way to do this from Lua is to use debug.setmetatable
.
The whole point of __metatable
is protection. The debug library bypasses this protection (and others) and should be used with care, of course.
Upvotes: 5