加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Lua __metatable绕过?

发布时间:2020-12-14 21:43:29 所属栏目:大数据 来源:网络整理
导读:我想知道是否有办法逃避__metatable元方法.我知道没有一个,但我正在尝试做这样的事情,但显然__metatable会阻止这种情况发生: -- pretend that there is a __metatable field given to a table setmetatable(_G,{__index = {None="No indexes"}}) -- error:
我想知道是否有办法逃避__metatable元方法.我知道没有一个,但我正在尝试做这样的事情,但显然__metatable会阻止这种情况发生:

-- 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)

我在这里尝试做的只是逃避__metatable字段,只是允许自己在_G上设置metatable,它已经有一个.
我知道这是不可能做到的,但是我想问一下是否还有机会绕过?

解决方法

从Lua执行此操作的唯一方法是使用debug.setmetatable.

__metatable的重点是保护.调试库绕过了这种保护(和其他),当然应该谨慎使用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读