如果我正確理解這一點,那麼當發生錯誤時,Lua默認會調用調試庫「debug.traceback」。從嵌入lua的C代碼打印堆棧跟蹤
然而,嵌入的Lua爲C代碼的時候喜歡在這裏的例子做: Simple Lua API Example
我們只有在堆棧的頂部的錯誤消息。
即
if (status) {
/* If something went wrong, error message is at the top of */
/* the stack */
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
/* I want to print a stacktrace here. How do I do that? */
exit(1);
}
如何打印從C堆棧跟蹤初始誤差後?
在Lua 5.2中,你可以使用luaL_traceback。 – lhf