Print stacktrace from C code with embedded lua

后端 未结 4 1944
温柔的废话
温柔的废话 2020-12-31 01:54

If I understand this correctly, Lua by default will call the debug library \"debug.traceback\" when an error occurs.

However, when embedding Lua into C code like don

4条回答
  •  有刺的猬
    2020-12-31 02:55

    I met the some question as you do,and I found this way work:

    luaL_traceback(L, L, NULL, 1);
    printf("%s\n", lua_tostring(L, -1));
    

    SinceluaL_tracebackis exactlydebug.traceback() using to print the stack,so I think this may be a proper way,and you can read the API manual aboutluaL_traceback or just read the source code of Lua to figure out the what the params means.

提交回复
热议问题