From: John L. <jr...@us...> - 2007-11-30 23:00:44
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22316/wxLua/modules/wxluadebug/src Modified Files: wxldebug.cpp wxlstack.cpp Log Message: - wxLuaStackDialog has better search for all columns, collapse and expand tables, and show metatables. It also now uses a virtual wxListCtrl so it's much faster. - Separated the "tags" for C++ classes from "refs" for objects we want a handle on in the Lua registry by putting them in separate tables. - Removed wxlua_pushkey_XXX #defines since we now have a few tables in the registry that we use and those methods were not useful anymore. The lightuserdata keys are now const char* strings with a descriptive name, however only the mem address is used as the table key. - wxluaT_newtag() now leaves the created table on the stack. - Removed wxluaT_newweaktag() and wxluaT_settagmethod() since they were not needed anymore. Index: wxlstack.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxlstack.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** wxlstack.cpp 30 Nov 2007 06:23:39 -0000 1.19 --- wxlstack.cpp 30 Nov 2007 23:00:08 -0000 1.20 *************** *** 44,47 **** --- 44,150 ---- #define WXLUAARG_WXLUADATA (WXLUAARG__MIN - 100) + + // ---------------------------------------------------------------------------- + // wxLuaStackListCtrl + // ---------------------------------------------------------------------------- + + class wxLuaStackListCtrl : public wxListCtrl + { + public: + wxLuaStackListCtrl( wxLuaStackDialog* stkDialog, + wxWindow *parent, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxLC_REPORT, + const wxValidator& validator = wxDefaultValidator, + const wxString &name = wxT("wxLuaStackListCtrl")) + : wxListCtrl(parent, winid, pos, size, style, validator, name) + { + m_stkDlg = stkDialog; + } + + virtual wxString OnGetItemText(long item, long column) const; + virtual int OnGetItemImage(long item) const; + virtual int OnGetItemColumnImage(long item, long column) const; + virtual wxListItemAttr *OnGetItemAttr(long item) const; + + wxListItemAttr m_itemAttr; + wxLuaStackDialog* m_stkDlg; + }; + + + wxString wxLuaStackListCtrl::OnGetItemText(long item, long column) const + { + wxLuaStackListData* stkListData = (wxLuaStackListData*)m_stkDlg->m_listData[item]; + wxCHECK_MSG(stkListData, wxEmptyString, wxT("Invalid wxLuaStackListData item")); + wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); + wxCHECK_MSG(debugItem, wxEmptyString, wxT("Invalid wxLuaDebugItem item")); + + switch (column) + { + case 0: + if (stkListData->m_level > 0) + { + wxString s(wxT("-->")); + for (int i = 1; i < stkListData->m_level; ++i) s += wxT("-->"); + return s + debugItem->GetKey(); + } + else + return debugItem->GetKey(); + case 1: + return wxString::Format(wxT("%d:%d"), stkListData->m_level+1, stkListData->m_item_idx+1); + case 2: + return debugItem->GetKeyTypeString(); + case 3: + return debugItem->GetValueTypeString(); + case 4: + { + wxString value(debugItem->GetValue()); + if (value.Length() > 200) value = value.Mid(0, 200) + wxT("... <snip>"); + value.Replace(wxT("\n"), wxT("\\n")); + value.Replace(wxT("\r"), wxT("\\r")); + return value; + } + } + + return wxEmptyString; + } + int wxLuaStackListCtrl::OnGetItemImage(long item) const + { + return -1; + } + int wxLuaStackListCtrl::OnGetItemColumnImage(long item, long column) const + { + if (column == 0) + { + wxLuaStackListData* stkListData = (wxLuaStackListData*)m_stkDlg->m_listData[item]; + wxCHECK_MSG(stkListData, NULL, wxT("Invalid wxLuaStackListData item")); + wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); + wxCHECK_MSG(debugItem, NULL, wxT("Invalid wxLuaDebugItem item")); + + return m_stkDlg->GetItemImage(debugItem); + } + + return -1; + } + wxListItemAttr *wxLuaStackListCtrl::OnGetItemAttr(long item) const + { + wxLuaStackListData* stkListData = (wxLuaStackListData*)m_stkDlg->m_listData[item]; + wxCHECK_MSG(stkListData, NULL, wxT("Invalid wxLuaStackListData item")); + wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); + wxCHECK_MSG(debugItem, NULL, wxT("Invalid wxLuaDebugItem item")); + + int img = m_stkDlg->GetItemImage(debugItem); + + wxLuaStackListCtrl* stkCtrl = (wxLuaStackListCtrl*)this; // unconst + + stkCtrl->m_itemAttr.SetTextColour(m_stkDlg->m_typeColours[img]); + //SetBackgroundColour + + return &stkCtrl->m_itemAttr; + } + + // ---------------------------------------------------------------------------- // wxLuaStackDialog *************** *** 71,76 **** EVT_LIST_ITEM_ACTIVATED( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnListItemActivated) EVT_LIST_ITEM_RIGHT_CLICK( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnListRightClick) - EVT_LIST_DELETE_ITEM( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnListItemDeleted) - EVT_LIST_DELETE_ALL_ITEMS( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnListAllItemsDeleted) END_EVENT_TABLE() --- 174,177 ---- *************** *** 89,93 **** m_show_dup_expand_msg = true; m_batch_count = 0; - m_skip_tree_event = false; } --- 190,193 ---- *************** *** 238,244 **** m_treeCtrl->SetImageList(m_imageList); ! m_listCtrl = new wxListCtrl(m_splitterWin, ID_WXLUA_STACK_LISTCTRL, wxDefaultPosition, wxDefaultSize, ! wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES ); m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); --- 338,344 ---- m_treeCtrl->SetImageList(m_imageList); ! m_listCtrl = new wxLuaStackListCtrl(this, m_splitterWin, ID_WXLUA_STACK_LISTCTRL, wxDefaultPosition, wxDefaultSize, ! wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES|wxLC_VIRTUAL ); m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); *************** *** 331,335 **** } ! int wxLuaStackDialog::SetupListItem(const wxLuaDebugItem *dbgItem, wxListItem& lItem) { wxCHECK_MSG(dbgItem, IMG_UNKNOWN, wxT("Invalid wxLuaDebugItem")); --- 431,435 ---- } ! int wxLuaStackDialog::GetItemImage(const wxLuaDebugItem *dbgItem) { wxCHECK_MSG(dbgItem, IMG_UNKNOWN, wxT("Invalid wxLuaDebugItem")); *************** *** 360,382 **** img = IMG_TABLE; - lItem.SetImage(img); - lItem.SetTextColour(m_typeColours[img]); - - /* - // Adjust the fonts to highlight some types - wxFont f(m_listCtrl->GetFont()); - - if ((img == IMG_TABLE) || (img == IMG_TABLE_OPEN)) - { - f.SetWeight(wxFONTWEIGHT_BOLD); - lItem.SetFont(f); - } - else if (img == IMG_STRING) - { - f.SetStyle(wxFONTSTYLE_ITALIC); - lItem.SetFont(f); - } - */ - return img; } --- 460,463 ---- *************** *** 445,449 **** RemoveAllLuaReferences(); DeleteAllListItemData(); ! m_listCtrl->DeleteAllItems(); m_treeCtrl->DeleteAllItems(); --- 526,531 ---- RemoveAllLuaReferences(); DeleteAllListItemData(); ! m_expandedItems.clear(); ! m_listCtrl->SetItemCount(0); m_treeCtrl->DeleteAllItems(); *************** *** 493,500 **** // If less than the count we're expanding a item, else adding a new root ! if (lc_item_ < m_listCtrl->GetItemCount()) { // Set the children data for the parent ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listCtrl->GetItemData(lc_item_); wxCHECK_RET((stkListData != NULL), wxT("The wxLuaStackDialog does have stack data!")); wxCHECK_RET(!stkListData->m_childrenDebugData.Ok() || (stkListData->m_childrenDebugData == debugData), wxT("Replacing the child data?")); --- 575,582 ---- // If less than the count we're expanding a item, else adding a new root ! if (lc_item_ < (long)m_listData.GetCount()) { // Set the children data for the parent ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[lc_item_]; wxCHECK_RET((stkListData != NULL), wxT("The wxLuaStackDialog does have stack data!")); wxCHECK_RET(!stkListData->m_childrenDebugData.Ok() || (stkListData->m_childrenDebugData == debugData), wxT("Replacing the child data?")); *************** *** 505,515 **** if (!treeId) treeId = m_treeCtrl->GetRootItem(); ! wxString levelText(m_listCtrl->GetItemText(lc_item_).BeforeLast(wxT('>'))); ! if (levelText.Length() > 0) ! levelStr = levelText + wxT(">--> "); ! else ! levelStr = levelText + wxT("--> "); ! ! level = (levelStr.Length()-1)/3; } else --- 587,591 ---- if (!treeId) treeId = m_treeCtrl->GetRootItem(); ! level = stkListData->m_level+1; } else *************** *** 522,544 **** BeginBatch(); - m_skip_tree_event = true; size_t n, count = debugData.GetCount(); long lc_item = lc_item_; for (n = 0; n < count; ++n) { ! const wxLuaDebugItem *item = debugData.Item(n); ! //wxPrintf(wxT("FillTableEntry %ld %ld n %d %ld '%s'\n"), lc_item_, lc_item, n, (long)item, item->GetName().c_str()); ! wxListItem info; ! info.SetId(lc_item+1); ! info.SetText(levelStr + item->GetKey()); ! wxLuaStackListData* stkListData = new wxLuaStackListData(n, debugData); ! info.SetData(stkListData); // we must delete this ! int img = SetupListItem(item, info); if ((img == IMG_TABLE) || (img == IMG_TABLE_OPEN)) { ! wxTreeItemId id = m_treeCtrl->AppendItem(treeId, item->GetKey(), -1, -1, new wxLuaStackTreeData(stkListData)); m_treeCtrl->SetItemHasChildren(id); stkListData->m_treeId = id; --- 598,618 ---- BeginBatch(); + bool removed_tree_dummy = false; size_t n, count = debugData.GetCount(); + long lc_item = lc_item_; for (n = 0; n < count; ++n) { ! wxLuaStackListData* stkListData = new wxLuaStackListData(n, level, debugData); ! m_listData.Insert(stkListData, lc_item+n+1); ! wxLuaDebugItem* debugItem = debugData.Item(n); ! ! int img = GetItemImage(debugItem); if ((img == IMG_TABLE) || (img == IMG_TABLE_OPEN)) { ! wxTreeItemId id = m_treeCtrl->AppendItem(treeId, debugItem->GetKey(), -1, -1, new wxLuaStackTreeData(stkListData)); m_treeCtrl->SetItemHasChildren(id); stkListData->m_treeId = id; *************** *** 550,574 **** // now that we've added something, remove the first dummy " " item from parent ! wxTreeItemIdValue dummyCookie; ! wxTreeItemId dummyId = m_treeCtrl->GetFirstChild(treeId, dummyCookie); ! if (m_treeCtrl->GetItemText(dummyId) == DUMMY_TREEITEM) ! m_treeCtrl->Delete(dummyId); ! } ! ! lc_item = m_listCtrl->InsertItem(info); ! info.SetId(lc_item); ! ! m_listCtrl->SetItem(lc_item, 1, wxString::Format(wxT("%d:%d"), level+1, n+1)); ! m_listCtrl->SetItem(lc_item, 2, item->GetKeyTypeString()); ! m_listCtrl->SetItem(lc_item, 3, item->GetValueTypeString()); ! // generic listctrl doesn't like showing huge strings, nor \n ! wxString value(item->GetValue()); ! if (value.Length() > 200) value = value.Mid(0, 200) + wxT("... <snip>"); ! value.Replace(wxT("\n"), wxT("\\n")); ! value.Replace(wxT("\r"), wxT("\\r")); ! m_listCtrl->SetItem(lc_item, 4, value); } EndBatch(); --- 624,641 ---- // now that we've added something, remove the first dummy " " item from parent ! if (!removed_tree_dummy) ! { ! removed_tree_dummy = true; ! wxTreeItemIdValue dummyCookie; ! wxTreeItemId dummyId = m_treeCtrl->GetFirstChild(treeId, dummyCookie); ! if (m_treeCtrl->GetItemText(dummyId) == DUMMY_TREEITEM) ! m_treeCtrl->Delete(dummyId); ! } ! } } + m_listCtrl->SetItemCount(m_listData.GetCount()); + EndBatch(); *************** *** 581,587 **** m_treeCtrl->Expand(treeId); #endif //!defined(WXLUA_STACK_MSWTREE) - - m_skip_tree_event = false; - } } --- 648,651 ---- *************** *** 609,613 **** dataArr.Add(destroyItem); ! FillTableEntry(m_listCtrl->GetItemCount(), dataArr); } --- 673,677 ---- dataArr.Add(destroyItem); ! FillTableEntry(m_listData.GetCount(), dataArr); } *************** *** 667,671 **** for (n = 0; n < count; n++) { ! stkListData_n = (wxLuaStackListData*)m_listCtrl->GetItemData(n); if (!get_parent && (stkListData_n == stkListData)) --- 731,735 ---- for (n = 0; n < count; n++) { ! stkListData_n = (wxLuaStackListData*)m_listData[n]; if (!get_parent && (stkListData_n == stkListData)) *************** *** 678,718 **** } - void wxLuaStackDialog::DoExpandCollapse(const wxTreeItemId& item, bool expand, wxProgressDialog* dlg, long& counter) - { - if (counter < 0) // allows for immediate exit, see below - return; - - if (dlg && (counter % 20 == 0)) - { - wxString msg; - if (expand) - msg.Printf(wxT("Expanding nodes : %ld"), counter); - else - msg.Printf(wxT("Collapsing nodes : %ld"), counter); - - if (!dlg->Pulse(msg)) - { - counter = -1; - return; - } - } - - if (expand) - m_treeCtrl->Expand(item); - - // then (recursively) expand all the children - wxTreeItemIdValue cookie; - for ( wxTreeItemId idCurr = m_treeCtrl->GetFirstChild(item, cookie); - idCurr.IsOk(); - idCurr = m_treeCtrl->GetNextChild(item, cookie) ) - { - DoExpandCollapse(idCurr, expand, dlg, ++counter); - } - - if (!expand) - m_treeCtrl->Collapse(item); - } - - void wxLuaStackDialog::OnExpandButton(wxCommandEvent &event) { --- 742,745 ---- *************** *** 721,729 **** if (start_item < 0) return; ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listCtrl->GetItemData(start_item); ! wxTreeItemId treeId = stkListData->m_treeId; ! ! bool expand = event.GetId() == ID_WXLUA_STACK_EXPAND_BUTTON; wxString caption; --- 748,754 ---- if (start_item < 0) return; + wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[start_item]; ! bool expand = (event.GetId() == ID_WXLUA_STACK_EXPAND_BUTTON); wxString caption; *************** *** 734,744 **** wxProgressDialog dlg(caption, wxEmptyString, 100, this, ! wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT); m_show_dup_expand_msg = false; BeginBatch(); ! long counter = 0; ! DoExpandCollapse(treeId, expand, &dlg, counter); EndBatch(); --- 759,797 ---- wxProgressDialog dlg(caption, wxEmptyString, 100, this, ! wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT); m_show_dup_expand_msg = false; BeginBatch(); ! // Note: Iterating through all of the listctrl items, even though most of ! // them are not expandable, is MUCH faster than using the far fewer ! // wxTreeCtrl items and calling Expand() on them. ! ! int counter = 0; ! int n = start_item, level = stkListData->m_level; ! while (n < (int)m_listData.GetCount()) ! { ! wxLuaStackListData* stkListData_n = (wxLuaStackListData*)m_listData[n]; ! ! if ((n > start_item) && (stkListData_n->m_level <= level)) break; ! ! if (counter % 20 == 0) ! { ! wxString msg; ! if (expand) ! msg.Printf(wxT("Expanding nodes : %d"), counter); ! else ! msg.Printf(wxT("Collapsing nodes : %d"), counter); ! ! if (!dlg.Pulse(msg)) ! break; ! } ! ! if (!stkListData_n->GetDebugItem()->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) ! ExpandItem(n); ! ! counter++; ! n++; ! } EndBatch(); *************** *** 932,936 **** void wxLuaStackDialog::OnTreeItem(wxTreeEvent &event) { ! if (m_skip_tree_event) return; wxTreeItemId id = event.GetItem(); --- 985,989 ---- void wxLuaStackDialog::OnTreeItem(wxTreeEvent &event) { ! if (m_batch_count > 0) return; wxTreeItemId id = event.GetItem(); *************** *** 964,968 **** void wxLuaStackDialog::OnListItemActivated(wxListEvent &event) { ! wxLuaStackListData* stkListData = (wxLuaStackListData*)event.GetData(); wxCHECK_RET(stkListData != NULL, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); --- 1017,1021 ---- void wxLuaStackDialog::OnListItemActivated(wxListEvent &event) { ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[event.GetIndex()]; wxCHECK_RET(stkListData != NULL, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); *************** *** 1014,1018 **** bool expanded = false; ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listCtrl->GetItemData(lc_item); wxCHECK_MSG(stkListData != NULL, false, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); --- 1067,1071 ---- bool expanded = false; ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[lc_item]; wxCHECK_MSG(stkListData != NULL, false, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); *************** *** 1048,1100 **** if (m_expandedItems[vkey]) { ! if (m_show_dup_expand_msg) ! { ! wxMessageBox(wxT("Cannot expand linked tables,\nplease see the already expanded table."), ! wxT("wxLua Stack"), wxOK | wxCENTRE, this); ! ! long n = m_listCtrl->FindItem(0, (long)m_expandedItems[vkey]); ! ! m_listCtrl->SetItemState(n, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); ! m_listCtrl->SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); ! m_listCtrl->EnsureVisible(n); ! } ! ! return false; ! } ! ! /* ! long n, count = m_listCtrl->GetItemCount(); ! for (n = 0; n < count; n++) ! { ! wxLuaStackListData* stkListData_n = (wxLuaStackListData*)m_listCtrl->GetItemData(n); ! wxCHECK_MSG(stkListData_n != NULL, false, wxT("Invalid wxLuaStack data")); ! wxLuaDebugItem* debugItem_n = stkListData_n->GetDebugItem(); ! ! if (debugItem_n && (debugItem_n != debugItem) && ! debugItem_n->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED) && ! (debugItem_n->GetValue() == val)) { ! if (m_show_dup_expand_msg) ! { ! wxMessageBox(wxT("Cannot expand linked tables,\nplease see the already expanded table."), ! wxT("wxLua Stack"), wxOK | wxCENTRE, this); ! m_listCtrl->SetItemState(n, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); ! m_listCtrl->SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); ! m_listCtrl->EnsureVisible(n); ! } ! return false; } } - */ } // Check our special variables for the wxLuaState data if (m_wxlState.Ok() && ! ((debugItem->GetKey() == _("Tracked User Data")) || ! (debugItem->GetKey() == _("wxEvent Callbacks")) || ! (debugItem->GetKey() == _("Top Level wxWindows")) || ! (debugItem->GetKey() == _("wxWindow Destroy List")))) { wxLuaState wxlState(m_wxlState); --- 1101,1129 ---- if (m_expandedItems[vkey]) { ! if (m_show_dup_expand_msg) { ! wxMessageBox(wxT("Cannot expand linked tables,\nplease see the already expanded table."), ! wxT("wxLua Stack"), wxOK | wxCENTRE, this); ! int n = m_listData.Index((void*)m_expandedItems[vkey]); ! wxCHECK_MSG(n != wxNOT_FOUND, false, wxT("Unable to find hash of expanded items.")); ! m_listCtrl->SetItemState(n, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); ! m_listCtrl->SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); ! m_listCtrl->EnsureVisible(n); } + + return false; } } + wxString key(debugItem->GetKey()); + // Check our special variables for the wxLuaState data if (m_wxlState.Ok() && ! ((key == _("Tracked User Data")) || ! (key == _("wxEvent Callbacks")) || ! (key == _("Top Level wxWindows")) || ! (key == _("wxWindow Destroy List")))) { wxLuaState wxlState(m_wxlState); *************** *** 1127,1131 **** { debugItem->SetFlagBit(WXLUA_DEBUGITEM_EXPANDED, true); - m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); wxString val(debugItem->GetValue()); --- 1156,1159 ---- *************** *** 1150,1154 **** bool collapsed = false; ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listCtrl->GetItemData(lc_item); wxCHECK_MSG(stkListData != NULL, false, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); --- 1178,1182 ---- bool collapsed = false; ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[lc_item]; wxCHECK_MSG(stkListData != NULL, false, wxT("Invalid wxLuaStack data")); wxLuaDebugItem* debugItem = stkListData->GetDebugItem(); *************** *** 1167,1172 **** for (n = lc_item+1; n < count; n++) { ! wxLuaStackListData* stkListData_n = (wxLuaStackListData*)m_listCtrl->GetItemData(n); wxCHECK_MSG(stkListData_n != NULL, false, wxT("Invalid wxLuaStack data")); if (stkListData_n->m_parentDebugData == childData) { --- 1195,1201 ---- for (n = lc_item+1; n < count; n++) { ! wxLuaStackListData* stkListData_n = (wxLuaStackListData*)m_listData[n]; wxCHECK_MSG(stkListData_n != NULL, false, wxT("Invalid wxLuaStack data")); + if (stkListData_n->m_parentDebugData == childData) { *************** *** 1174,1180 **** stkListData_n->GetDebugItem()->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) { CollapseItem(n); ! n = (n > 2) ? (n - 2) : -1; continue; } --- 1203,1214 ---- stkListData_n->GetDebugItem()->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) { + wxString val(stkListData_n->GetDebugItem()->GetValue()); + long vkey = 0; + if (val.BeforeFirst(wxT(' ')).ToLong(&vkey, 16)) + m_expandedItems.erase(vkey); + CollapseItem(n); ! n--; count = m_listData.GetCount(); continue; } *************** *** 1182,1188 **** collapsed = true; // only if we removed anything ! m_listCtrl->DeleteItem(n); ! n = (n > 2) ? (n - 2) : -1; // back up and try again ! count = m_listCtrl->GetItemCount(); } } --- 1216,1228 ---- collapsed = true; // only if we removed anything ! if (stkListData_n->m_treeId) ! m_treeCtrl->Delete(stkListData_n->m_treeId); ! ! m_listData.RemoveAt(n); ! ! if (stkListData_n != NULL) ! delete stkListData_n; ! ! n--; count = m_listData.GetCount(); } } *************** *** 1200,1236 **** wxString val(debugItem->GetValue()); long vkey = 0; ! wxCHECK_MSG(val.BeforeFirst(wxT(' ')).ToLong(&vkey, 16), false, wxT("Invalid table item")); ! m_expandedItems.erase(vkey); } EndBatch(); ! return collapsed; ! } ! ! void wxLuaStackDialog::OnListItemDeleted(wxListEvent &event) ! { ! wxLuaStackListData* stkListData = (wxLuaStackListData*)event.GetData(); ! wxCHECK_RET(stkListData != NULL, wxT("wxLuaStackDialog::OnItemDeleted not handled")); ! ! wxString val(stkListData->GetDebugItem()->GetValue()); ! long vkey = 0; ! val.BeforeFirst(wxT(' ')).ToLong(&vkey, 16); ! m_expandedItems.erase(vkey); ! ! // make sure that we don't forget any items... ! if (stkListData->m_treeId) ! m_treeCtrl->Delete(stkListData->m_treeId); ! m_listCtrl->SetItemData(event.GetIndex(), 0); // null it so we won't try to delete it again ! if (stkListData != NULL) ! delete stkListData; ! } ! void wxLuaStackDialog::OnListAllItemsDeleted(wxListEvent &event) ! { ! RemoveAllLuaReferences(); ! DeleteAllListItemData(); ! m_expandedItems.clear(); ! event.Skip(); } --- 1240,1252 ---- wxString val(debugItem->GetValue()); long vkey = 0; ! if (val.BeforeFirst(wxT(' ')).ToLong(&vkey, 16)) ! m_expandedItems.erase(vkey); } EndBatch(); ! m_listCtrl->SetItemCount(m_listData.GetCount()); ! return collapsed; } *************** *** 1239,1251 **** m_expandedItems.clear(); ! long i, count = m_listCtrl->GetItemCount(); ! for (i = 0; i < count; i++) { ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listCtrl->GetItemData(i); - m_listCtrl->SetItemData(i, 0); // null it so we won't try to delete it again if (stkListData != NULL) delete stkListData; } } --- 1255,1269 ---- m_expandedItems.clear(); ! int i, count = m_listData.GetCount(); ! ! for (i = 0; i < count; ++i) { ! wxLuaStackListData* stkListData = (wxLuaStackListData*)m_listData[i]; if (stkListData != NULL) delete stkListData; } + + m_listData.Clear(); } *************** *** 1283,1289 **** */ ! for (i = 0; i < (int)m_luaReferences.GetCount(); ++i) { ! bool ok = m_wxlState.wxluaT_Remove(m_luaReferences[i]); wxCHECK_RET(ok, wxT("Unable to remove a reference in Lua")); //wxPrintf(wxT("Extra Lua reference in listctrl #%d ok %d ref %d count %d\n"), i, ok, m_luaReferences[i], m_luaReferences.GetCount()); --- 1301,1308 ---- */ ! // remove the last to so we don't make any holes ! for (i = (int)m_luaReferences.GetCount()-1; i >= 0; --i) { ! bool ok = m_wxlState.wxluaT_Remove(m_luaReferences[i], &wxlua_lreg_debug_refs_key); wxCHECK_RET(ok, wxT("Unable to remove a reference in Lua")); //wxPrintf(wxT("Extra Lua reference in listctrl #%d ok %d ref %d count %d\n"), i, ok, m_luaReferences[i], m_luaReferences.GetCount()); *************** *** 1291,1293 **** --- 1310,1347 ---- m_luaReferences.Clear(); + + // ---------------------------------------------------------------------- + // Sanity check to make sure that we've cleared all the references + // There should be only one of us created at any time. + + lua_State* L = m_wxlState.GetLuaState(); + //wxLuaCheckStack cs(L, wxT("wxLuaStackDialog::RemoveAllLuaReferences")); + lua_pushlightuserdata(L, &wxlua_lreg_debug_refs_key); // push name of table to get as key + lua_rawget(L, LUA_REGISTRYINDEX); // pop key, push result (the refs table) + + lua_pushnil(L); + while (lua_next(L, -2) != 0) // ref table can have holes in it + { + // value = -1, key = -2, table = -3 + if (!lua_isnumber(L, -2)) + wxPrintf(wxT("wxLuaStackDialog::RemoveAllLuaReferences refs not empty key=%d value=%d\n"), lua_type(L, -2), lua_type(L, -1)); + else if ((lua_tonumber(L, -2) == 0) && (lua_tonumber(L, -1) != 1)) + wxPrintf(wxT("wxLuaStackDialog::RemoveAllLuaReferences refs not empty key=%lf value=%lg\n"), lua_tonumber(L, -2), lua_tonumber(L, -1)); + + lua_pop(L, 1); // pop value, lua_next will pop key at end + } + + lua_pop(L, 1); // pop ref table + + // Clear out the old numeric references since it should be "empty" + // though full of table[idx]=next_idx, where table[0] = 1; + + lua_pushlightuserdata(L, &wxlua_lreg_debug_refs_key); // push name of table to get as key + lua_pushnil(L); + lua_rawset(L, LUA_REGISTRYINDEX); // clear the table completely + + // create the debug refs table in registry + lua_pushlightuserdata(L, &wxlua_lreg_debug_refs_key); + lua_newtable(L); + lua_rawset(L, LUA_REGISTRYINDEX); // set the value } Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** wxldebug.cpp 30 Nov 2007 06:23:39 -0000 1.50 --- wxldebug.cpp 30 Nov 2007 23:00:08 -0000 1.51 *************** *** 271,275 **** { // push the table onto the stack to iterate through ! if (wxlState.wxluaT_Get(tableRef)) { if (lua_getmetatable(L, -1)) // if no metatable then nothing is pushed --- 271,275 ---- { // push the table onto the stack to iterate through ! if (wxlState.wxluaT_Get(tableRef, &wxlua_lreg_debug_refs_key)) { if (lua_getmetatable(L, -1)) // if no metatable then nothing is pushed *************** *** 320,329 **** if (lua_istable(L, stack_idx)) { ! nRef = wxluaT_isrefed(L, stack_idx); // don't duplicate refs if (nRef == LUA_NOREF) { if (flag_type) *flag_type |= WXLUA_DEBUGITEM_LUAREFED; ! nRef = wxluaT_insert(L, -1); references.Add(nRef); } --- 320,329 ---- if (lua_istable(L, stack_idx)) { ! nRef = wxluaT_isrefed(L, stack_idx, &wxlua_lreg_debug_refs_key); // don't duplicate refs if (nRef == LUA_NOREF) { if (flag_type) *flag_type |= WXLUA_DEBUGITEM_LUAREFED; ! nRef = wxluaT_insert(L, -1, &wxlua_lreg_debug_refs_key); references.Add(nRef); } *************** *** 388,400 **** case LUA_TFUNCTION: { if (lua_iscfunction(L, stack_idx)) - { wxl_type = WXLUAARG_CFunction; ! value.Printf(wxT("%p"), lua_tocfunction(L, stack_idx)); ! } ! else ! { ! value.Printf(wxT("%p"), lua_topointer(L, stack_idx)); ! } break; } --- 388,396 ---- case LUA_TFUNCTION: { + value.Printf(wxT("%p"), lua_topointer(L, stack_idx)); + if (lua_iscfunction(L, stack_idx)) wxl_type = WXLUAARG_CFunction; ! break; } *************** *** 439,443 **** } ! wxString wxLuaDebugData::GetUserDataInfo(const wxLuaState& wxlState, int stack_idx, bool full) { wxCHECK_MSG(wxlState.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); --- 435,439 ---- } ! wxString wxLuaDebugData::GetUserDataInfo(const wxLuaState& wxlState, int stack_idx, bool full_userdata) { wxCHECK_MSG(wxlState.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); *************** *** 448,471 **** wxString s(wxString::Format(wxT("%p"), udata)); ! if (!full) { // Convert our known keys to something more readable ! if (udata == &wxlua_lreg_references_key) ! s += wxT(" - wxLua References"); ! else if (udata == &wxlua_lreg_classes_key) ! s += wxT(" - wxLuaBindClasses"); ! else if (udata == &wxlua_lreg_derivedmethods_key) ! s += wxT(" - wxLua Derived Class Methods"); ! else if (udata == &wxlua_lreg_wxluastate_key) ! s += wxT(" - wxLuaState"); ! else if (udata == &wxlua_lreg_objects_key) ! s += wxT(" - wxLua Pushed Userdata"); ! else if (udata == &wxlua_lreg_callbaseclassfunc_key) ! s += wxT(" - CallBaseClassFunc"); ! ! else if (udata == &wxlua_lreg_metatable_tag_key) ! s += wxT(" - wxLua Metatable Class Tag"); ! else if (udata == &wxlua_lreg_metatable_class_key) ! s += wxT(" - wxLua Metatable wxLuaBindClass"); } else // is full userdata --- 444,464 ---- wxString s(wxString::Format(wxT("%p"), udata)); ! if (!full_userdata) { // Convert our known keys to something more readable ! if ((udata == &wxlua_lreg_tags_key) || ! (udata == &wxlua_lreg_refs_key) || ! (udata == &wxlua_lreg_debug_refs_key) || ! (udata == &wxlua_lreg_classes_key) || ! (udata == &wxlua_lreg_derivedmethods_key) || ! (udata == &wxlua_lreg_wxluastate_key) || ! (udata == &wxlua_lreg_callbaseclassfunc_key) || ! (udata == &wxlua_lreg_objects_key) || ! (udata == &wxlua_metatable_tag_key) || ! (udata == &wxlua_metatable_wxluabindclass_key)) ! { ! const char* ss = *(const char**)udata; ! s += wxString::Format(wxT(" : %s"), lua2wx(ss).c_str()); ! } } else // is full userdata |