Lua checks库- pcall丢失函数名

我开始在我们的RPC接口中使用LuaJIT的checks库。

但是当传递错误的参数时,RPC调用使用pcall,而checks无法获取函数名。

相反,它会抛出像这样的错误信息:

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……你会如何做到这一点?

点赞