diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-27 08:30:54 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-27 08:30:54 +0000 |
commit | d7ca99b68de9b08ae4d6be0ad6d9db1eb5a62aa2 (patch) | |
tree | c0428dad2c625d8c1acbfae8d38edc1006416e2c /crawl-ref/source/clua.cc | |
parent | c5ce2cf3dba395aba2d497d56adbea759dd79677 (diff) | |
download | crawl-ref-d7ca99b68de9b08ae4d6be0ad6d9db1eb5a62aa2.tar.gz crawl-ref-d7ca99b68de9b08ae4d6be0ad6d9db1eb5a62aa2.zip |
Added functions print_dlua_stack() and print_clua_stack(), which can
be called from the debugger to print the call stacks of the dlua interpreter
and the clua interpreter. Code borrowed from ToME 3 (code I originally
wrote, so borrowing is definitely okay).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7651 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/clua.cc')
-rw-r--r-- | crawl-ref/source/clua.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 3be3f4398e..a87a1070f5 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -3180,3 +3180,31 @@ bool lua_datum::is_udata() const { LUA_CHECK_TYPE(lua_isuserdata); } + +// Can be called from within a debugger to look at the current Lua +// call stack. (Borrowed from ToME 3) +void print_clua_stack(void) +{ + struct lua_Debug dbg; + int i = 0; + lua_State *L = clua.state(); + + fprintf(stderr, "\n"); + while (lua_getstack(L, i++, &dbg) == 1) + { + lua_getinfo(L, "lnuS", &dbg); + + char* file = strrchr(dbg.short_src, '/'); + if (file == NULL) + file = dbg.short_src; + else + file++; + + // Have to use "\r\n" instead of just "\n" here, for some + // reason. + fprintf(stderr, "%s, function %s, line %d\r\n", file, + dbg.name, dbg.currentline); + } + + fprintf(stderr, "\n"); +} |