小编Ber*_*ver的帖子

Lua __metatable绕过?

我想知道是否有办法逃避__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)
Run Code Online (Sandbox Code Playgroud)

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

lua metatable meta-method

4
推荐指数
1
解决办法
541
查看次数

C++类型标识符

好的,如果我在C++头函数中执行此操作:

#include <iostream>
#include <string>
using namespace std;
// Prerequisites ^
int main(){
    int io_print([Here's what I need help with]){};
};
Run Code Online (Sandbox Code Playgroud)

我知道代码示例完全是语法错误,但我需要帮助的是尝试使用允许整数,浮点数和字符串的类型.所以我可以简单地做io_print(40)和io_print("Hi").我试过这个,根本找不到允许这种类型的任何类型,如果有任何机会知道答案,那么请回复.

我正在这样做,因为我想重新定义功能.请不要问为什么.

c++ c++11

3
推荐指数
1
解决办法
337
查看次数

标签 统计

c++ ×1

c++11 ×1

lua ×1

meta-method ×1

metatable ×1