Lua检查库 - pcall丢失函数名

时间:2017-05-03 04:04:29

标签: lua luajit

我已经开始在luajit中使用check库来获取我们拥有的RPC接口。

但RPC调用使用pcall,当传递错误的参数时,检查无法获取函数名称。

相反,它会抛出一条错误消息,如:

bad argument #3 to (null) (number expected, got nil)

而不是

bad argument #3 to (foo) (number expected, got nil)

打开调试工具。

#if 1 /* Debugging cruft */
    int i;
    for(i=0;i<10;i++){
        if( ! lua_getstack( L, i, & ar)) break;
        lua_getinfo( L, "n", & ar);
        printf( "\tat level %d: '%s' / '%s'\n", i, ar.name, ar.namewhat);
    }
    printf( "\tend of error, level was %d\n\n", level);
#endif

结果:

    at level 0: 'checks' / 'global'
    at level 1: '(null)' / ''
    at level 2: 'pcall' / 'global'
    at level 3: 'Run' / 'local'
    at level 4: '(null)' / ''
    end of error, level was 1

false    bad argument #3 to (null) (number expected, got nil)

因此,调用pcall,但null是函数的名称。

我是否正确地认为,如果找到函数“pcall”而不是在级别1显示为null,则pcall函数的第一个参数需要从级别2替换。但我不明白Lua API ......你会怎么做?

0 个答案:

没有答案
相关问题