From 71f33c97d88cb5cd5801ead10daf263d9fffffa0 Mon Sep 17 00:00:00 2001 From: Dave Schuyler Date: Tue, 6 Apr 2004 23:54:22 +0000 Subject: [PATCH] Added traceFunctionCall --- direct/src/showbase/PythonUtil.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index f3f996b775..51d70914f1 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -30,6 +30,36 @@ def indent(stream, numIndents, str): # To match emacs, instead of a tab character we will use 4 spaces stream.write(' ' * numIndents + str) +def traceFunctionCall(frame): + """ + return a string that shows the call frame with calling arguments. + e.g. + foo(x=234, y=135) + """ + f = frame + co = f.f_code + dict = f.f_locals + n = co.co_argcount + if co.co_flags & 4: n = n+1 + if co.co_flags & 8: n = n+1 + r=f.f_code.co_name+'(' + for i in range(n): + name = co.co_varnames[i] + if name=='self': + continue + if i: + r+=', ' + r+=name + r+='=' + if dict.has_key(name): + v=str(dict[name]) + if len(v)>200: + r+="" + else: + r+=str(dict[name]) + else: r+="*** undefined ***" + return r+')' + def apropos(obj, *args): """ Obsolete, use pdir