Print stacktrace from C code with embedded lua

Posted by Matt H on Stack Overflow See other posts from Stack Overflow or by Matt H
Published on 2012-09-04T03:33:43Z Indexed on 2012/09/04 3:38 UTC
Read the original article Hit count: 199

Filed under:

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 done in the example here: Simple Lua API Example

We only have available the error message on the top of the stack.

i.e.

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);
}

How do I print the stack trace from C after the initial error?

© Stack Overflow or respective owner

Related posts about lua