00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef WX_LUA_DEBUG_H
00010 #define WX_LUA_DEBUG_H
00011
00012 #include "wx/dynarray.h"
00013 #include "wx/treectrl.h"
00014
00015 #include "wxluadebug/include/wxluadebugdefs.h"
00016 #include "wxlua/include/wxlstate.h"
00017
00018 class WXDLLIMPEXP_WXLUADEBUG wxLuaDebugData;
00019
00020
00021
00022
00023
00024
00025
00026
00027 enum wxLuaDebugItem_Type
00028 {
00029 WXLUA_DEBUGITEM_LOCALS = 0x0100,
00030
00031 WXLUA_DEBUGITEM_EXPANDED = 0x0200,
00032
00033 WXLUA_DEBUGITEM_IS_REFED = 0x1000,
00034
00035 WXLUA_DEBUGITEM_KEY_REF = 0x2000,
00036 WXLUA_DEBUGITEM_VALUE_REF = 0x4000,
00037 };
00038
00039 class WXDLLIMPEXP_WXLUADEBUG wxLuaDebugItem
00040 {
00041 public:
00042 wxLuaDebugItem(const wxLuaDebugItem &debugDataItem);
00043 wxLuaDebugItem(const wxString &itemKey, int itemKeyType,
00044 const wxString &itemValue, int itemValueType,
00045 const wxString &itemSource,
00046 int lua_ref, int idx = 0, int flag = 0);
00047
00048
00049 wxString GetKey() const { return m_itemKey; }
00050 int GetKeyType() const { return m_itemKeyType; }
00051 wxString GetKeyTypeString() const { return wxluaT_typename(NULL, m_itemKeyType); }
00052
00053
00054 wxString GetValue() const { return m_itemValue; }
00055 int GetValueType() const { return m_itemValueType; }
00056 wxString GetValueTypeString() const { return wxluaT_typename(NULL, m_itemValueType); }
00057
00058
00059 wxString GetSource() const { return m_itemSource; }
00060
00061 int GetRef() const { return m_lua_ref; }
00062 int GetIndex() const { return m_index; }
00063 int GetFlag() const { return m_flag; }
00064 bool GetFlagBit(int mask) const { return WXLUA_HASBIT(m_flag, mask); }
00065
00066
00067
00068
00069 bool GetRefPtr(long& ptr) const;
00070
00071 void SetFlag(int flag) { m_flag = flag; }
00072 void SetFlagBit(int bit, bool set) { m_flag = WXLUA_SETBIT(m_flag, bit, set); }
00073 void SetRef(int lua_ref) { m_lua_ref = lua_ref; }
00074
00075
00076 wxString ToString() const
00077 {
00078 return wxString::Format(wxT("Key: '%s' KeyType: %d '%s' Value: '%s' ValueType: %d '%s' Ref: %d Idx: %d Flag: %x HasSrc: %d"),
00079 m_itemKey.c_str(), m_itemKeyType, GetKeyTypeString().c_str(),
00080 m_itemValue.c_str(), m_itemValueType, GetValueTypeString().c_str(),
00081 m_lua_ref, m_index, m_flag, (int)!m_itemSource.IsEmpty());
00082 }
00083
00084
00085
00086 wxString m_itemKey;
00087 int m_itemKeyType;
00088 wxString m_itemValue;
00089 int m_itemValueType;
00090 wxString m_itemSource;
00091 int m_lua_ref;
00092 int m_index;
00093 int m_flag;
00094 };
00095
00096 #if defined(WXMAKINGDLL_WXLUADEBUG) || defined(WXUSINGDLL)
00097 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(wxLuaDebugItem *, wxLuaDebugItemArray, WXDLLIMPEXP_WXLUADEBUG);
00098 #else
00099 WX_DEFINE_SORTED_ARRAY(wxLuaDebugItem *, wxLuaDebugItemArray);
00100 #endif
00101
00102
00103
00104
00105
00106
00107
00108 extern WXDLLIMPEXP_DATA_WXLUADEBUG(wxLuaDebugData) wxNullLuaDebugData;
00109
00110 class WXDLLIMPEXP_WXLUADEBUG wxLuaDebugData : public wxObject
00111 {
00112 public:
00113 wxLuaDebugData(bool create);
00114 wxLuaDebugData(const wxLuaDebugData &debugData) { Ref(debugData); }
00115
00116 virtual ~wxLuaDebugData() {}
00117
00118
00119 bool Ok() const { return (m_refData != NULL); }
00120
00121
00122 wxLuaDebugItemArray* GetArray();
00123 const wxLuaDebugItemArray* GetArray() const;
00124
00125
00126
00127
00128 size_t GetCount() const;
00129 wxLuaDebugItem* Item(size_t index) const;
00130 void Add(wxLuaDebugItem* item);
00131
00132
00133
00134
00135
00136 int EnumerateStack(const wxLuaState& wxlState);
00137
00138
00139 int EnumerateStackEntry(const wxLuaState& wxlState, int stack_frame, wxArrayInt& references);
00140
00141
00142 int EnumerateTable(const wxLuaState& wxlState, int nRef, int nEntry, wxArrayInt& references);
00143
00144
00145
00146
00147
00148
00149
00150 static int GetTypeValue(const wxLuaState& wxlState, int stack_idx, int* wxl_type, wxString& value);
00151
00152 static wxString GetTableInfo(const wxLuaState& wxlState, int stack_idx);
00153
00154
00155 static wxString GetUserDataInfo(const wxLuaState& wxlState, int stack_idx, bool full_userdata);
00156
00157
00158
00159
00160 wxLuaDebugData Copy() const;
00161
00162
00163 int RefTable(lua_State* L, int stack_idx, int* flag_type, int extra_flag, wxArrayInt& references);
00164
00165
00166 static int SortFunction(wxLuaDebugItem *elem1, wxLuaDebugItem *elem2 );
00167
00168
00169 bool operator == (const wxLuaDebugData& debugData) const
00170 { return m_refData == debugData.m_refData; }
00171 bool operator != (const wxLuaDebugData& debugData) const
00172 { return m_refData != debugData.m_refData; }
00173
00174 wxLuaDebugData& operator = (const wxLuaDebugData& debugData)
00175 {
00176 if ( (*this) != debugData )
00177 Ref(debugData);
00178 return *this;
00179 }
00180 };
00181
00182
00183
00184
00185
00186 class WXDLLIMPEXP_WXLUADEBUG wxLuaCheckStack
00187 {
00188 public:
00189
00190
00191
00192
00193 wxLuaCheckStack(lua_State* L, const wxString &msg = wxEmptyString, bool print_to_console = true);
00194
00195 ~wxLuaCheckStack();
00196
00197
00198 wxString TestStack(const wxString &msg = wxEmptyString);
00199
00200
00201 wxString DumpStack(const wxString& msg = wxEmptyString);
00202
00203
00204 wxString DumpGlobals(const wxString& msg = wxEmptyString);
00205
00206
00207 wxString DumpTable(const wxString& tableName, const wxString& msg = wxEmptyString);
00208
00209 wxString DumpTable(int stack_idx, const wxString& msg = wxEmptyString);
00210
00211
00212
00213
00214 wxString DumpTable(int stack_idx, const wxString& tablename, const wxString& msg, wxSortedArrayString& tableArray, int indent);
00215
00216
00217 void OutputMsg(const wxString& msg) const;
00218
00219
00220
00221 lua_State* m_luaState;
00222 wxString m_msg;
00223 int m_top;
00224 bool m_print_to_console;
00225 };
00226
00227 #endif // WX_LUA_DEBUG_H