From: John L. <jr...@us...> - 2007-05-31 17:18:57
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv14219/wxLua/modules/wxluadebug/src Modified Files: wxldebug.cpp wxlstack.cpp Log Message: Huge changes, overloaded functions by default replace wx.wxNull with wx.NULL change WXLUA_VERSION and others with wxLUA_VERSION class member enums are part of class table static class member functions are part of class table %properties are generated on the fly ... and more, see docs/changelog.txt Index: wxlstack.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxlstack.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** wxlstack.cpp 24 May 2007 00:59:47 -0000 1.1 --- wxlstack.cpp 31 May 2007 17:18:54 -0000 1.2 *************** *** 35,42 **** BEGIN_EVENT_TABLE(wxLuaStackDialog, wxDialog) ! EVT_COMBOBOX( ID_WXLUA_STACKDIALOG_COMBO, wxLuaStackDialog::OnSelectStack) ! EVT_LIST_ITEM_ACTIVATED( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnItemActivated) ! EVT_LIST_DELETE_ITEM( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnItemDeleted) ! EVT_LIST_DELETE_ALL_ITEMS( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnAllItemsDeleted) END_EVENT_TABLE() --- 35,49 ---- BEGIN_EVENT_TABLE(wxLuaStackDialog, wxDialog) ! EVT_CHOICE( ID_WXLUA_STACK_CHOICE, wxLuaStackDialog::OnSelectStack) ! ! EVT_BUTTON( ID_WXLUA_STACK_EXPAND_BUTTON, wxLuaStackDialog::OnExpandButton) ! ! EVT_TEXT_ENTER( ID_WXLUA_STACK_FIND_COMBO, wxLuaStackDialog::OnFind) ! EVT_BUTTON( ID_WXLUA_STACK_FINDNEXT_BUTTON, wxLuaStackDialog::OnFind) ! EVT_BUTTON( ID_WXLUA_STACK_FINDPREV_BUTTON, wxLuaStackDialog::OnFind) ! ! EVT_LIST_ITEM_ACTIVATED( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnItemActivated) ! EVT_LIST_DELETE_ITEM( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnItemDeleted) ! EVT_LIST_DELETE_ALL_ITEMS( ID_WXLUA_STACK_LISTCTRL, wxLuaStackDialog::OnAllItemsDeleted) END_EVENT_TABLE() *************** *** 44,49 **** { m_listCtrl = NULL; ! m_stackComboBox = NULL; m_stack_sel = -1; m_imageList = NULL; --- 51,58 ---- { m_listCtrl = NULL; ! m_stackChoice = NULL; m_stack_sel = -1; + m_findComboBox = NULL; + m_findCaseCheckBox = NULL; m_imageList = NULL; *************** *** 61,109 **** return false; wxPanel* panel = new wxPanel(this, wxID_ANY); ! m_stackComboBox = new wxComboBox( panel, ID_WXLUA_STACKDIALOG_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, ! 0, NULL, ! wxCB_DROPDOWN | wxCB_READONLY); ! m_listCtrl = new wxListCtrl( panel, ID_WXLUA_STACKDIALOG_LISTCTRL, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES ); m_listCtrl->InsertColumn(0, wxT("Name"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->InsertColumn(1, wxT("Type"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->InsertColumn(2, wxT("Value"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->SetColumnWidth(0, 250); ! m_listCtrl->SetColumnWidth(1, 100); ! m_listCtrl->SetColumnWidth(2, 100); ! m_imageList = new wxImageList(16, 16, true); ! m_imageList->Add(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); // unknown ! m_imageList->Add(wxArtProvider::GetIcon(wxART_FOLDER, wxART_TOOLBAR, wxSize(16,16))); // table ! m_imageList->Add(wxArtProvider::GetIcon(wxART_NEW_DIR, wxART_TOOLBAR, wxSize(16,16))); // open table wxBitmap bmp(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); ! m_imageList->Add(CreateBmpString(bmp, wxT("0"))); // nil ! m_imageList->Add(CreateBmpString(bmp, wxT("T"))); // bool ! m_imageList->Add(CreateBmpString(bmp, wxT("1"))); // number ! m_imageList->Add(CreateBmpString(bmp, wxT("a"))); // string ! m_imageList->Add(CreateBmpString(bmp, wxT("C"))); // C function ! m_imageList->Add(CreateBmpString(bmp, wxT("f"))); // Lua function ! m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // user data ! m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // light user data ! m_imageList->Add(CreateBmpString(bmp, wxT("t"))); // thread m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); ! // set the frame icon ! SetIcon(wxICON(LUA)); // use sizers to layout the windows in the panel of the dialog wxBoxSizer* rootSizer = new wxBoxSizer(wxVERTICAL); ! rootSizer->Add(m_stackComboBox, 0, wxEXPAND|wxBOTTOM, 4); rootSizer->Add(m_listCtrl, 1, wxEXPAND); rootSizer->SetMinSize(450, 400); --- 70,194 ---- return false; + SetIcon(wxICON(LUA)); // set the frame icon + wxPanel* panel = new wxPanel(this, wxID_ANY); ! // ----------------------------------------------------------------------- ! ! wxStaticText* stackText = new wxStaticText( panel, wxID_ANY, wxT("Stack : ")); ! ! m_stackChoice = new wxChoice( panel, ID_WXLUA_STACK_CHOICE, ! wxDefaultPosition, wxDefaultSize, ! 0, NULL ); ! m_stackChoice->SetToolTip(wxT("Select lua stack to display.")); ! ! wxButton* expandButton = new wxButton(panel, ID_WXLUA_STACK_EXPAND_BUTTON, ! wxT("Expand All")); ! expandButton->SetToolTip(wxT("Expand all tables.")); ! ! // ----------------------------------------------------------------------- ! ! wxStaticText* findText = new wxStaticText( panel, wxID_ANY, wxT("Find : ")); ! m_findComboBox = new wxComboBox( panel, ID_WXLUA_STACK_FIND_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, ! 0, NULL, wxCB_DROPDOWN | wxTE_PROCESS_ENTER); ! m_findComboBox->SetToolTip(wxT("Enter variable name or table key to find")); ! wxBitmapButton* findPrev = new wxBitmapButton( panel, ID_WXLUA_STACK_FINDPREV_BUTTON, ! wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_BUTTON)); ! wxBitmapButton* findNext = new wxBitmapButton( panel, ID_WXLUA_STACK_FINDNEXT_BUTTON, ! wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_BUTTON)); ! findPrev->SetToolTip(wxT("Find previous instance")); ! findNext->SetToolTip(wxT("Find next instance")); ! ! m_findCaseCheckBox = new wxCheckBox(panel, ID_WXLUA_STACK_FINDCASE_CHECKBOX, ! wxT("Case")); ! m_findCaseCheckBox->SetValue(true); ! m_findCaseCheckBox->SetToolTip(wxT("Match case when finding")); ! ! // ----------------------------------------------------------------------- ! ! wxFlexGridSizer* topSizer = new wxFlexGridSizer(2, 1); ! topSizer->AddGrowableCol(1); ! ! topSizer->Add(stackText, wxSizerFlags().Expand().Border().Align(wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL)); ! ! wxFlexGridSizer* stackSizer = new wxFlexGridSizer(2, 1); ! stackSizer->AddGrowableCol(0); ! stackSizer->Add(m_stackChoice, wxSizerFlags().Expand().Border()); ! stackSizer->Add(expandButton, wxSizerFlags().Border()); ! topSizer->Add(stackSizer, wxSizerFlags().Expand()); ! ! topSizer->Add(findText, wxSizerFlags().Expand().Border().Align(wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL)); ! ! wxFlexGridSizer* findSizer = new wxFlexGridSizer(4, 1); ! findSizer->AddGrowableCol(0); ! findSizer->Add(m_findComboBox, wxSizerFlags().Expand().Border()); ! findSizer->Add(findPrev, wxSizerFlags().Expand().Border()); ! findSizer->Add(findNext, wxSizerFlags().Expand().Border()); ! findSizer->Add(m_findCaseCheckBox, wxSizerFlags().Expand().Border()); ! ! topSizer->Add(findSizer, wxSizerFlags().Expand()); ! ! // ----------------------------------------------------------------------- ! ! m_listCtrl = new wxListCtrl( panel, ID_WXLUA_STACK_LISTCTRL, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES ); m_listCtrl->InsertColumn(0, wxT("Name"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->InsertColumn(1, wxT("Level"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->InsertColumn(2, wxT("Type"), wxLIST_FORMAT_LEFT, -1); ! m_listCtrl->InsertColumn(3, wxT("Value"), wxLIST_FORMAT_LEFT, -1); ! int txt_width = 0, txt_height = 0; ! m_listCtrl->GetTextExtent(wxT("WWWWWWWWWWWWWWWWWWWW"), &txt_width, &txt_height); ! m_listCtrl->SetColumnWidth(0, txt_width); ! m_listCtrl->SetColumnWidth(3, txt_width); // make it wide since it's the last ! m_listCtrl->GetTextExtent(wxT("55:5555"), &txt_width, &txt_height); ! m_listCtrl->SetColumnWidth(1, txt_width); ! m_listCtrl->GetTextExtent(wxT("Light User DataX"), &txt_width, &txt_height); ! m_listCtrl->SetColumnWidth(2, txt_width); ! m_imageList = new wxImageList(16, 16, true); wxBitmap bmp(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); ! m_imageList->Add(bmp); // IMG_UNKNOWN ! m_imageList->Add(bmp); // IMG_NONE ! m_imageList->Add(CreateBmpString(bmp, wxT("0"))); // IMG_NIL ! m_imageList->Add(CreateBmpString(bmp, wxT("b"))); // IMG_BOOLEAN ! m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // IMG_LIGHTUSERDATA ! m_imageList->Add(CreateBmpString(bmp, wxT("1"))); // IMG_NUMBER ! m_imageList->Add(CreateBmpString(bmp, wxT("s"))); // IMG_STRING ! m_imageList->Add(wxArtProvider::GetIcon(wxART_FOLDER, wxART_TOOLBAR, wxSize(16,16))); // IMG_TABLE ! m_imageList->Add(CreateBmpString(bmp, wxT("f"))); // IMG_LUAFUNCTION ! m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // IMG_USERDATA ! m_imageList->Add(CreateBmpString(bmp, wxT("t"))); // IMG_THREAD ! m_imageList->Add(CreateBmpString(bmp, wxT("c"))); // IMG_CFUNCTION ! m_imageList->Add(wxArtProvider::GetIcon(wxART_NEW_DIR, wxART_TOOLBAR, wxSize(16,16))); // IMG_TABLE_OPEN m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); ! m_typeColours[IMG_UNKNOWN] = wxColour(wxT("TURQUOISE")); ! m_typeColours[IMG_NONE] = wxColour(wxT("TURQUOISE")); ! m_typeColours[IMG_NIL] = wxColour(wxT("BLACK")); ! m_typeColours[IMG_BOOLEAN] = wxColour(wxT("FIREBRICK")); ! m_typeColours[IMG_LIGHTUSERDATA]= wxColour(wxT("CORNFLOWER BLUE")); ! m_typeColours[IMG_NUMBER] = wxColour(wxT("DARK ORCHID")); ! m_typeColours[IMG_STRING] = wxColour(wxT("RED")); ! m_typeColours[IMG_TABLE] = wxColour(wxT("BLUE")); ! m_typeColours[IMG_LUAFUNCTION] = wxColour(wxT("MEDIUM FOREST GREEN")); ! m_typeColours[IMG_USERDATA] = wxColour(wxT("CORNFLOWER BLUE")); ! m_typeColours[IMG_THREAD] = wxColour(wxT("BLACK")); ! m_typeColours[IMG_CFUNCTION] = wxColour(wxT("FOREST GREEN")); ! m_typeColours[IMG_TABLE_OPEN] = wxColour(wxT("BLUE")); ! ! // ----------------------------------------------------------------------- // use sizers to layout the windows in the panel of the dialog wxBoxSizer* rootSizer = new wxBoxSizer(wxVERTICAL); ! rootSizer->Add(topSizer, 0, wxEXPAND|wxBOTTOM, 5); rootSizer->Add(m_listCtrl, 1, wxEXPAND); rootSizer->SetMinSize(450, 400); *************** *** 160,202 **** } ! int wxLuaStackDialog::SetupListItem(const wxLuaDebugDataItem *dbgItem, wxListItem& lItem) { ! wxCHECK_MSG(dbgItem, IMG_UNKNOWN, wxT("Invalid wxLuaDebugDataItem")); ! ! wxString t(dbgItem->GetType()); ! int n, img = IMG_UNKNOWN; ! ! wxChar* strTypes[IMG_THREAD+1] = { ! wxT(""), // unknown ! wxT("Table"), ! wxT(""), // table open ! wxT("Nil"), ! wxT("Boolean"), ! wxT("Number"), ! wxT("String"), ! wxT("C Function"), ! wxT("Lua Function"), ! wxT("User Data"), ! wxT("Light User Data"), ! wxT("Thread") ! }; ! for (n = 0; n < IMG_THREAD+1; n++) ! { ! if (t == strTypes[n]) ! { ! img = n; ! break; ! } ! } // now fix up the images for special cases ! if (dbgItem->GetExpanded()) img = IMG_TABLE_OPEN; ! else if (t == wxT("wxLuaData")) // our internal data structs img = IMG_TABLE; lItem.SetImage(img); // Adjust the fonts to highlight some types wxFont f(m_listCtrl->GetFont()); --- 245,264 ---- } ! int wxLuaStackDialog::SetupListItem(const wxLuaDebugItem *dbgItem, wxListItem& lItem) { ! wxCHECK_MSG(dbgItem, IMG_UNKNOWN, wxT("Invalid wxLuaDebugItem")); ! int img = dbgItem->GetTypeN(); // now fix up the images for special cases ! if (dbgItem->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) img = IMG_TABLE_OPEN; ! else if (dbgItem->GetType() == wxT("wxLuaData")) // our internal data structs img = IMG_TABLE; lItem.SetImage(img); + lItem.SetTextColour(m_typeColours[img]); + /* // Adjust the fonts to highlight some types wxFont f(m_listCtrl->GetFont()); *************** *** 212,215 **** --- 274,278 ---- lItem.SetFont(f); } + */ return img; *************** *** 251,255 **** void wxLuaStackDialog::FillStackCombobox(const wxLuaDebugData& debugData) { ! m_stackComboBox->Clear(); m_stackEntries.Clear(); --- 314,318 ---- void wxLuaStackDialog::FillStackCombobox(const wxLuaDebugData& debugData) { ! m_stackChoice->Clear(); m_stackEntries.Clear(); *************** *** 257,268 **** for (n = 0; n < count; ++n) { ! const wxLuaDebugDataItem *item = debugData.Item(n); ! m_stackEntries.Add(item->GetReference()); ! m_stackComboBox->Append(item->GetName()); } if (debugData.GetCount() > 0) { ! m_stackComboBox->SetSelection(0); SelectStack(0); } --- 320,331 ---- for (n = 0; n < count; ++n) { ! const wxLuaDebugItem *item = debugData.Item(n); ! m_stackEntries.Add(item->GetIndex()); ! m_stackChoice->Append(item->GetName()); } if (debugData.GetCount() > 0) { ! m_stackChoice->SetSelection(0); SelectStack(0); } *************** *** 275,279 **** // Add the locals, fake a debug item to get it setup right ! wxLuaDebugDataItem* localItem = new wxLuaDebugDataItem(_("Locals"), wxT("Table"), wxString::Format(wxT("Count %d"), (int)debugData.GetCount()), wxT(""), 0, 0); wxLuaDebugData dataArr; // this deletes the items dataArr.Add(localItem); --- 338,344 ---- // Add the locals, fake a debug item to get it setup right ! wxLuaDebugItem* localItem = new wxLuaDebugItem(_("Locals"), wxT("Table"), ! wxString::Format(wxT("Count %d"), (int)debugData.GetCount()), ! wxT(""), LUA_NOREF, 0, WXLUA_DEBUGITEM_EXPANDED); wxLuaDebugData dataArr; // this deletes the items dataArr.Add(localItem); *************** *** 300,303 **** --- 365,369 ---- { wxString levelStr; + int level = 0; // If less than the count we're expanding a item, else adding a new root *************** *** 309,312 **** --- 375,380 ---- else levelStr = levelText + wxT("--> "); + + level = (levelStr.Length()-1)/3; } else *************** *** 317,321 **** for (n = 0; n < count; ++n) { ! const wxLuaDebugDataItem *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()); --- 385,389 ---- 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()); *************** *** 323,327 **** info.SetId(lc_item+1); info.SetText(levelStr + item->GetName()); ! info.SetData(new wxLuaDebugDataItem(*item)); SetupListItem(item, info); --- 391,395 ---- info.SetId(lc_item+1); info.SetText(levelStr + item->GetName()); ! info.SetData(new wxLuaDebugItem(*item)); SetupListItem(item, info); *************** *** 329,334 **** info.SetId(lc_item); ! m_listCtrl->SetItem(lc_item, 1, item->GetType()); ! m_listCtrl->SetItem(lc_item, 2, item->GetValue()); } } --- 397,404 ---- 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->GetType()); ! m_listCtrl->SetItem(lc_item, 3, item->GetValue()); } } *************** *** 346,353 **** // note: don't have spaces here since we use them to mark expanded levels ! wxLuaDebugDataItem* trackedItem = new wxLuaDebugDataItem(_("Tracked User Data"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), trackedCount), wxT(""), 1, 0); ! wxLuaDebugDataItem* callbackItem = new wxLuaDebugDataItem(_("wxEvent Callbacks"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), callbackCount), wxT(""), 1, 0); ! wxLuaDebugDataItem* windowItem = new wxLuaDebugDataItem(_("Top Level wxWindows"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), windowCount), wxT(""), 1, 0); ! wxLuaDebugDataItem* destroyItem = new wxLuaDebugDataItem(_("wxWindow Destroy List"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), destroyCount), wxT(""), 1, 0); wxLuaDebugData dataArr; // this deletes the items --- 416,423 ---- // note: don't have spaces here since we use them to mark expanded levels ! wxLuaDebugItem* trackedItem = new wxLuaDebugItem(_("Tracked User Data"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), trackedCount), wxT(""), LUA_NOREF, 0); ! wxLuaDebugItem* callbackItem = new wxLuaDebugItem(_("wxEvent Callbacks"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), callbackCount), wxT(""), LUA_NOREF, 0); ! wxLuaDebugItem* windowItem = new wxLuaDebugItem(_("Top Level wxWindows"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), windowCount), wxT(""), LUA_NOREF, 0); ! wxLuaDebugItem* destroyItem = new wxLuaDebugItem(_("wxWindow Destroy List"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), destroyCount), wxT(""), LUA_NOREF, 0); wxLuaDebugData dataArr; // this deletes the items *************** *** 362,366 **** void wxLuaStackDialog::OnItemDeleted(wxListEvent &event) { ! wxLuaDebugDataItem* wxlDItem = (wxLuaDebugDataItem*)event.GetData(); if (wxlDItem != NULL) delete wxlDItem; --- 432,436 ---- void wxLuaStackDialog::OnItemDeleted(wxListEvent &event) { ! wxLuaDebugItem* wxlDItem = (wxLuaDebugItem*)event.GetData(); if (wxlDItem != NULL) delete wxlDItem; *************** *** 372,375 **** --- 442,574 ---- } + void wxLuaStackDialog::OnExpandButton(wxCommandEvent &event) + { + wxBusyCursor wait; + + int level = 0; + int level_count = 1; + + while (level_count > 0) + { + level_count = 0; + + for (long i = 0; i < m_listCtrl->GetItemCount(); ++i) + { + wxString s(m_listCtrl->GetItemText(i)); + if (s.Find(wxT("--> _G")) == wxNOT_FOUND) + { + int cur_level = (s.BeforeLast(wxT('>')).Length() + 1) / 3; + if (cur_level == level) + { + level_count++; + ExpandItem(i, false); + } + } + } + + if (level_count > 0) + level++; + } + } + + // This code is copied from wxStEdit's function wxSTEPrependComboBoxString + void wxLuaPrependComboBoxString(const wxString &str, int max_strings, wxComboBox *combo) + { + wxCHECK_RET(combo, wxT("Invalid combobox in wxLuaPrependComboBoxString")); + + int pos = combo->FindString(str); + if (pos == 0) + return; + if (pos != wxNOT_FOUND) + combo->Delete(pos); + + #if wxCHECK_VERSION(2,5,0) + combo->Insert(str, 0); + #else + // note: can use SetString in MSW, but not in GTK + int n, count = combo->GetCount(); + wxArrayString strings; + strings.Alloc(count); + for (n = 0; n < count; n++) + strings.Add(combo->GetString(n)); + + combo->Clear(); + combo->Append(str); // put new string first + + for (n = 0; n < count; n++) + combo->Append(strings[n]); + #endif + + combo->SetSelection(0); + + if (max_strings > 0) + { + while ((int)combo->GetCount() > max_strings) + combo->Delete(combo->GetCount()-1); + } + } + + void wxLuaStackDialog::OnFind(wxCommandEvent &event) + { + wxString findStr = m_findComboBox->GetValue(); + if (findStr.IsEmpty()) + return; + + wxLuaPrependComboBoxString(findStr, 10, m_findComboBox); + + bool match_case = m_findCaseCheckBox->IsChecked(); + if (!match_case) findStr = findStr.Lower(); + + long direct = event.GetId() == ID_WXLUA_STACK_FINDPREV_BUTTON ? -1 : 1; + + long list_count = m_listCtrl->GetItemCount(); + long start_item = m_listCtrl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + + int loop_count = 0; + + while (loop_count < 2) + { + long i = 0; + bool found = false; + + if (loop_count == 0) + { + i = start_item + direct; + + // tweak up the starting item + if (start_item == -1) + { + i = direct > 0 ? 0 : list_count - 1; + loop_count++; // we're looking at all the elements + } + else if ((direct > 0) && (start_item == list_count - 1)) + { + i = 0; + loop_count++; // we're looking at all the elements + } + } + else + { + i = direct > 0 ? 0 : list_count - 1; + } + + for ( ; (i >= 0) && (i < list_count); i = i + direct) + { + if ((match_case && (m_listCtrl->GetItemText(i).Find(findStr) != wxNOT_FOUND)) || + (!match_case && (m_listCtrl->GetItemText(i).Lower().Find(findStr) != wxNOT_FOUND))) + { + m_listCtrl->SetItemState(i, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); + m_listCtrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + m_listCtrl->EnsureVisible(i); + found = true; + break; + } + } + + loop_count++; + if (found) break; + } + } + void wxLuaStackDialog::OnSelectStack(wxCommandEvent &event) { *************** *** 388,484 **** void wxLuaStackDialog::OnItemActivated(wxListEvent &event) { ! ItemExpanding(event.GetIndex()); //.GetIndex()); } ! void wxLuaStackDialog::ItemExpanding(long lc_item) { ! if (1) ! { ! wxLuaDebugDataItem *pDebugDataItem = (wxLuaDebugDataItem *)m_listCtrl->GetItemData(lc_item); ! // only expand items once ! if ((pDebugDataItem != NULL) && !pDebugDataItem->GetExpanded()) { ! // Check and block linked tables already shown ! if (pDebugDataItem->GetType() == wxT("Table")) ! { ! wxString val = pDebugDataItem->GetValue(); ! int n, count = m_listCtrl->GetItemCount(); ! for (n = 0; n < count; n++) { ! wxLuaDebugDataItem *itm = (wxLuaDebugDataItem *)m_listCtrl->GetItemData(n); ! if (itm && (itm != pDebugDataItem) && (itm->GetValue() == val) && itm->GetExpanded()) { 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; } } } ! int nRef = pDebugDataItem->GetReference(); ! if (m_wxlState.Ok() && ! ((pDebugDataItem->GetName() == _("Tracked User Data")) || ! (pDebugDataItem->GetName() == _("wxEvent Callbacks")) || ! (pDebugDataItem->GetName() == _("Top Level wxWindows")) || ! (pDebugDataItem->GetName() == _("wxWindow Destroy List")))) ! { ! wxLuaState wxlState(m_wxlState); ! wxArrayString names; ! wxArrayInt counts; ! if (pDebugDataItem->GetName() == _("Tracked User Data")) ! { ! wxLongToLongHashMap::iterator it; ! wxLongToLongHashMap* hashMap = wxlState.GetTrackedObjects(); ! for (it = hashMap->begin(); it != hashMap->end(); ++it) ! { ! wxString name(wxT("Unknown Tracked Item")); ! wxObject* obj = (wxObject*)it->second; ! if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) ! name = obj->GetClassInfo()->GetClassName(); ! //name = wxString::Format(wxT("%p "), obj) + name; ! int idx = names.Index(name); ! if (idx == wxNOT_FOUND) ! { ! names.Add(name); ! counts.Add(1); ! } ! else ! counts[idx]++; } } ! else if (pDebugDataItem->GetName() == _("wxEvent Callbacks")) { ! wxList::compatibility_iterator node = wxlState.GetTrackedCallbackList()->GetFirst(); ! while (node) ! { ! wxLuaCallback *pCallback = (wxLuaCallback *) node->GetData(); ! wxCHECK_RET(pCallback, wxT("Invalid wxLuaCallback")); ! wxString evtName; ! if (wxlState.GetLuaBindingList()) { ! wxLuaBindingList::compatibility_iterator bindNode = wxlState.GetLuaBindingList()->GetFirst(); ! for (; bindNode; bindNode = bindNode->GetNext()) ! { ! wxLuaBinding* binding = bindNode->GetData(); ! evtName = binding->GetEventTypeName(pCallback->GetEventType()); ! if (!evtName.IsEmpty()) break; ! } } ! wxString name = wxString::Format(wxT("%d %s"), (int)pCallback->GetEventType(), evtName.c_str()); int idx = names.Index(name); if (idx == wxNOT_FOUND) --- 587,715 ---- void wxLuaStackDialog::OnItemActivated(wxListEvent &event) { ! ExpandItem(event.GetIndex()); //.GetIndex()); } ! bool wxLuaStackDialog::ExpandItem(long lc_item, bool show_err_msg) { ! wxCHECK_MSG((lc_item >= 0) && (lc_item < m_listCtrl->GetItemCount()), false, ! wxT("Invalid list item to expand")); ! bool expanded = false; ! ! wxLuaDebugItem *pDebugDataItem = (wxLuaDebugItem *)m_listCtrl->GetItemData(lc_item); ! ! // only expand items once ! if ((pDebugDataItem != NULL) && !pDebugDataItem->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) ! { ! // Check and block linked tables already shown ! if (pDebugDataItem->GetType() == wxT("Table")) { ! wxString val = pDebugDataItem->GetValue(); ! int n, count = m_listCtrl->GetItemCount(); ! for (n = 0; n < count; n++) ! { ! wxLuaDebugItem *itm = (wxLuaDebugItem *)m_listCtrl->GetItemData(n); ! if (itm && (itm != pDebugDataItem) && (itm->GetValue() == val) && ! itm->GetFlagBit(WXLUA_DEBUGITEM_EXPANDED)) { ! if (show_err_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; } } + } ! int nRef = pDebugDataItem->GetReference(); ! // Check our special variables for the wxLuaState data ! if (m_wxlState.Ok() && ! ((pDebugDataItem->GetName() == _("Tracked User Data")) || ! (pDebugDataItem->GetName() == _("wxEvent Callbacks")) || ! (pDebugDataItem->GetName() == _("Top Level wxWindows")) || ! (pDebugDataItem->GetName() == _("wxWindow Destroy List")))) ! { ! wxLuaState wxlState(m_wxlState); ! wxArrayString names; ! wxArrayInt counts; ! if (pDebugDataItem->GetName() == _("Tracked User Data")) ! { ! wxLongToLongHashMap::iterator it; ! wxLongToLongHashMap* hashMap = wxlState.GetTrackedObjects(); ! for (it = hashMap->begin(); it != hashMap->end(); ++it) ! { ! wxString name(wxT("Unknown Tracked Item")); ! wxObject* obj = (wxObject*)it->second; ! if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) ! name = obj->GetClassInfo()->GetClassName(); ! //name = wxString::Format(wxT("%p "), obj) + name; ! ! int idx = names.Index(name); ! if (idx == wxNOT_FOUND) ! { ! names.Add(name); ! counts.Add(1); } + else + counts[idx]++; } ! } ! else if (pDebugDataItem->GetName() == _("wxEvent Callbacks")) ! { ! wxList::compatibility_iterator node = wxlState.GetTrackedCallbackList()->GetFirst(); ! while (node) { ! wxLuaCallback *pCallback = (wxLuaCallback *) node->GetData(); ! wxCHECK_MSG(pCallback, false, wxT("Invalid wxLuaCallback")); ! wxString evtName; ! if (wxlState.GetLuaBindingList()) ! { ! wxLuaBindingList::compatibility_iterator bindNode = wxlState.GetLuaBindingList()->GetFirst(); ! for (; bindNode; bindNode = bindNode->GetNext()) { ! wxLuaBinding* binding = bindNode->GetData(); ! evtName = binding->GetEventTypeName(pCallback->GetEventType()); ! if (!evtName.IsEmpty()) break; } + } ! wxString name = wxString::Format(wxT("%d %s"), (int)pCallback->GetEventType(), evtName.c_str()); ! int idx = names.Index(name); ! if (idx == wxNOT_FOUND) ! { ! names.Add(name); ! counts.Add(1); ! } ! else ! counts[idx]++; ! ! node = node->GetNext(); ! } ! } ! else if (pDebugDataItem->GetName() == _("Top Level wxWindows")) ! { ! wxWindowList::compatibility_iterator node = wxlState.GetLuaStateData()->m_windowList.GetFirst(); ! while (node) ! { ! wxWindow *win= (wxWindow*)node->GetData(); ! wxCHECK_MSG(win, false, wxT("Invalid wxLuaCallback")); ! if (win && win->GetClassInfo() && win->GetClassInfo()->GetClassName()) ! { ! wxString name(win->GetClassInfo()->GetClassName()); int idx = names.Index(name); if (idx == wxNOT_FOUND) *************** *** 489,563 **** else counts[idx]++; - - node = node->GetNext(); } - } - else if (pDebugDataItem->GetName() == _("Top Level wxWindows")) - { - wxWindowList::compatibility_iterator node = wxlState.GetLuaStateData()->m_windowList.GetFirst(); - while (node) - { - wxWindow *win= (wxWindow*)node->GetData(); - wxCHECK_RET(win, wxT("Invalid wxLuaCallback")); - if (win && win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - { - wxString name(win->GetClassInfo()->GetClassName()); - int idx = names.Index(name); - if (idx == wxNOT_FOUND) - { - names.Add(name); - counts.Add(1); - } - else - counts[idx]++; - } ! node = node->GetNext(); ! } } ! else if (pDebugDataItem->GetName() == _("wxWindow Destroy List")) { ! wxList::compatibility_iterator node = wxlState.GetTrackedWinDestroyCallbackList()->GetFirst(); ! while (node) ! { ! wxLuaWinDestroyCallback *pCallback = (wxLuaWinDestroyCallback *) node->GetData(); ! wxCHECK_RET(pCallback, wxT("Invalid wxLuaWinDestroyCallback")); ! wxString name(wxT("Unknown Tracked Window Type")); ! wxObject* obj = (wxObject*)pCallback->GetEvtHandler(); ! if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) ! name = obj->GetClassInfo()->GetClassName(); ! names.Add(name); ! counts.Add(1); ! node = node->GetNext(); ! } } ! pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); ! ! wxLuaDebugData dataArr; ! size_t n, count = names.GetCount(); ! for (n = 0; n < count; n++) ! { ! wxLuaDebugDataItem *item = new wxLuaDebugDataItem(names[n], wxT(""), wxString::Format(wxT("Count %d"), counts[n]), wxT(""), LUA_NOREF, pDebugDataItem->GetIndex() + 1); ! dataArr.Add(item); ! } ! FillTableEntry(lc_item, dataArr); ! } ! else if (nRef != LUA_NOREF) { ! pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); ! ! int nIndex = pDebugDataItem->GetIndex() + 1; ! EnumerateTable(nRef, nIndex, lc_item); } } } } --- 720,774 ---- else counts[idx]++; } ! node = node->GetNext(); } ! } ! else if (pDebugDataItem->GetName() == _("wxWindow Destroy List")) ! { ! wxList::compatibility_iterator node = wxlState.GetTrackedWinDestroyCallbackList()->GetFirst(); ! while (node) { ! wxLuaWinDestroyCallback *pCallback = (wxLuaWinDestroyCallback *) node->GetData(); ! wxCHECK_MSG(pCallback, false, wxT("Invalid wxLuaWinDestroyCallback")); ! wxString name(wxT("Unknown Tracked Window Type")); ! wxObject* obj = (wxObject*)pCallback->GetEvtHandler(); ! if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) ! name = obj->GetClassInfo()->GetClassName(); ! names.Add(name); ! counts.Add(1); ! node = node->GetNext(); } + } ! pDebugDataItem->SetFlagBit(WXLUA_DEBUGITEM_EXPANDED, true); ! m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); ! wxLuaDebugData dataArr; ! size_t n, count = names.GetCount(); ! for (n = 0; n < count; n++) { ! wxLuaDebugItem *item = new wxLuaDebugItem(names[n], wxT(""), wxString::Format(wxT("Count %d"), counts[n]), wxT(""), LUA_NOREF, pDebugDataItem->GetIndex() + 1); ! dataArr.Add(item); } + + FillTableEntry(lc_item, dataArr); + expanded = true; + } + else if (nRef != LUA_NOREF) + { + pDebugDataItem->SetFlagBit(WXLUA_DEBUGITEM_EXPANDED, true); + m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); + + int nIndex = pDebugDataItem->GetIndex() + 1; + EnumerateTable(nRef, nIndex, lc_item); } } + + return expanded; } *************** *** 567,571 **** for (i = 0; i < count; i++) { ! wxLuaDebugDataItem* wxlDItem = (wxLuaDebugDataItem*)m_listCtrl->GetItemData(i); m_listCtrl->SetItemData(i, 0); // null it so we won't try to delete it again if (wxlDItem != NULL) --- 778,782 ---- for (i = 0; i < count; i++) { ! wxLuaDebugItem* wxlDItem = (wxLuaDebugItem*)m_listCtrl->GetItemData(i); m_listCtrl->SetItemData(i, 0); // null it so we won't try to delete it again if (wxlDItem != NULL) Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** wxldebug.cpp 23 May 2007 02:48:31 -0000 1.30 --- wxldebug.cpp 31 May 2007 17:18:54 -0000 1.31 *************** *** 26,50 **** // ---------------------------------------------------------------------------- ! // wxLuaDebugDataItem // ---------------------------------------------------------------------------- ! wxLuaDebugDataItem::wxLuaDebugDataItem(const wxString &itemName, ! const wxString &itemType, ! const wxString &itemValue, ! const wxString &itemSource, ! int lua_ref, ! int idx, ! bool expanded) :m_itemName(itemName), m_itemType(itemType), m_itemValue(itemValue), m_itemSource(itemSource), m_lua_ref(lua_ref), m_index(idx), ! m_expanded(expanded) { } ! wxLuaDebugDataItem::wxLuaDebugDataItem(const wxLuaDebugDataItem &dataItem) ! :m_itemName(dataItem.m_itemName), m_itemType(dataItem.m_itemType), ! m_itemValue(dataItem.m_itemValue), m_itemSource(dataItem.m_itemSource), ! m_lua_ref(dataItem.m_lua_ref), m_index(dataItem.m_index), ! m_expanded(dataItem.m_expanded) { } --- 26,50 ---- // ---------------------------------------------------------------------------- ! // wxLuaDebugItem // ---------------------------------------------------------------------------- ! wxLuaDebugItem::wxLuaDebugItem(const wxString &itemName, ! const wxString &itemType, ! const wxString &itemValue, ! const wxString &itemSource, ! int lua_ref, ! int idx, ! int flag) :m_itemName(itemName), m_itemType(itemType), m_itemValue(itemValue), m_itemSource(itemSource), m_lua_ref(lua_ref), m_index(idx), ! m_flag(flag) { } ! wxLuaDebugItem::wxLuaDebugItem(const wxLuaDebugItem &dataItem) ! :m_itemName(dataItem.m_itemName), m_itemType(dataItem.m_itemType), ! m_itemValue(dataItem.m_itemValue), m_itemSource(dataItem.m_itemSource), ! m_lua_ref(dataItem.m_lua_ref), m_index(dataItem.m_index), ! m_flag(dataItem.m_flag) { } *************** *** 63,72 **** for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *pData = m_dataArray.Item(idx); delete pData; } } ! wxLuaDebugDataItemArray m_dataArray; }; --- 63,72 ---- for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugItem *pData = m_dataArray.Item(idx); delete pData; } } ! wxLuaDebugItemArray m_dataArray; }; *************** *** 76,87 **** { m_refData = new wxLuaDebugDataRefData; } ! wxLuaDebugDataItemArray* wxLuaDebugData::GetArray() { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); return &(M_DEBUGREFDATA->m_dataArray); } ! const wxLuaDebugDataItemArray* wxLuaDebugData::GetArray() const { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); --- 76,100 ---- { m_refData = new wxLuaDebugDataRefData; + + // Sanity check to make sure that lua hasn't changed the items on us + wxCHECK_RET((WXLUA_DEBUGITEM_TNONE == WXLUA_DEBUGITEM_T_SHIFT + LUA_TNONE) || + (WXLUA_DEBUGITEM_TNIL == WXLUA_DEBUGITEM_T_SHIFT + LUA_TNIL) || + (WXLUA_DEBUGITEM_TBOOLEAN == WXLUA_DEBUGITEM_T_SHIFT + LUA_TBOOLEAN) || + (WXLUA_DEBUGITEM_TLIGHTUSERDATA == WXLUA_DEBUGITEM_T_SHIFT + LUA_TLIGHTUSERDATA) || + (WXLUA_DEBUGITEM_TNUMBER == WXLUA_DEBUGITEM_T_SHIFT + LUA_TNUMBER) || + (WXLUA_DEBUGITEM_TSTRING == WXLUA_DEBUGITEM_T_SHIFT + LUA_TSTRING) || + (WXLUA_DEBUGITEM_TTABLE == WXLUA_DEBUGITEM_T_SHIFT + LUA_TTABLE) || + (WXLUA_DEBUGITEM_TFUNCTION == WXLUA_DEBUGITEM_T_SHIFT + LUA_TFUNCTION) || + (WXLUA_DEBUGITEM_TUSERDATA == WXLUA_DEBUGITEM_T_SHIFT + LUA_TUSERDATA) || + (WXLUA_DEBUGITEM_TTHREAD == WXLUA_DEBUGITEM_T_SHIFT + LUA_TTHREAD), + wxT("Lua has changed the order of their types.")); } ! wxLuaDebugItemArray* wxLuaDebugData::GetArray() { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); return &(M_DEBUGREFDATA->m_dataArray); } ! const wxLuaDebugItemArray* wxLuaDebugData::GetArray() const { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); *************** *** 94,106 **** return M_DEBUGREFDATA->m_dataArray.GetCount(); } ! wxLuaDebugDataItem* wxLuaDebugData::Item(size_t index) const { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); return M_DEBUGREFDATA->m_dataArray.Item(index); } ! void wxLuaDebugData::Add(wxLuaDebugDataItem* item) { wxCHECK_RET(M_DEBUGREFDATA != NULL, wxT("Invalid ref data")); ! wxCHECK_RET(item != NULL, wxT("Invalid wxLuaDebugDataItem")); M_DEBUGREFDATA->m_dataArray.Add(item); } --- 107,119 ---- return M_DEBUGREFDATA->m_dataArray.GetCount(); } ! wxLuaDebugItem* wxLuaDebugData::Item(size_t index) const { wxCHECK_MSG(M_DEBUGREFDATA != NULL, NULL, wxT("Invalid ref data")); return M_DEBUGREFDATA->m_dataArray.Item(index); } ! void wxLuaDebugData::Add(wxLuaDebugItem* item) { wxCHECK_RET(M_DEBUGREFDATA != NULL, wxT("Invalid ref data")); ! wxCHECK_RET(item != NULL, wxT("Invalid wxLuaDebugItem")); M_DEBUGREFDATA->m_dataArray.Add(item); } *************** *** 114,120 **** for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugDataItem *pOldData = M_DEBUGREFDATA->m_dataArray.Item(idx); if (pOldData != NULL) ! copyData.Add(new wxLuaDebugDataItem(*pOldData)); } --- 127,133 ---- for (idx = 0; idx < count; ++idx) { ! const wxLuaDebugItem *pOldData = M_DEBUGREFDATA->m_dataArray.Item(idx); if (pOldData != NULL) ! copyData.Add(new wxLuaDebugItem(*pOldData)); } *************** *** 122,126 **** } ! int wxLuaDebugData::SortFunction(wxLuaDebugDataItem *elem1, wxLuaDebugDataItem *elem2 ) { int ret = elem1->GetName().Cmp(elem2->GetName()); --- 135,139 ---- } ! int wxLuaDebugData::SortFunction(wxLuaDebugItem *elem1, wxLuaDebugItem *elem2 ) { int ret = elem1->GetName().Cmp(elem2->GetName()); *************** *** 167,172 **** name = wxString::Format(_("line %u"), currentLine); ! wxLuaDebugDataItem *item = new wxLuaDebugDataItem(name, wxT(""), wxT(""), source, nIndex, 0); ! Add(item); count++; } --- 180,184 ---- name = wxString::Format(_("line %u"), currentLine); ! Add(new wxLuaDebugItem(name, wxT(""), wxT(""), source, LUA_NOREF, nIndex, 0)); count++; } *************** *** 200,205 **** wxString value; wxString source(lua2wx(luaDebug.source)); ! GetTypeValue(wxlState, -1, type, value); int nRef = LUA_NOREF; --- 212,218 ---- wxString value; wxString source(lua2wx(luaDebug.source)); + int flag_type = WXLUA_DEBUGITEM_TUNKNOWN; ! GetTypeValue(wxlState, -1, type, value, &flag_type); int nRef = LUA_NOREF; *************** *** 213,217 **** lua_pop(L, 1); // remove variable value ! Add(new wxLuaDebugDataItem(name, type, value, source, nRef, 0)); count++; --- 226,230 ---- lua_pop(L, 1); // remove variable value ! Add(new wxLuaDebugItem(name, type, value, source, nRef, 0, flag_type)); count++; *************** *** 236,240 **** wxlState.GetGlobals(); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), wxT("Table"), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } --- 249,253 ---- wxlState.GetGlobals(); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugItem(wxT("Globals"), wxT("Table"), wxT(""), wxT(""), nRef, 0, WXLUA_DEBUGITEM_TTABLE)); references.Add(nRef); } *************** *** 243,246 **** --- 256,264 ---- if (wxlState.tget(tableRef)) { + wxString type; + wxString value; + wxString name; + int flag_type = WXLUA_DEBUGITEM_TUNKNOWN; + int nTop = lua_gettop(L); *************** *** 249,261 **** while (lua_next(L, nTop) != 0) { - wxString type; - wxString value; - wxString name; - wxString source; - // get the index, just want the name=value, type is dummy here GetTypeValue(wxlState, -2, type, name); // get the type and value ! GetTypeValue(wxlState, -1, type, value); int nRef = LUA_NOREF; --- 267,274 ---- while (lua_next(L, nTop) != 0) { // get the index, just want the name=value, type is dummy here GetTypeValue(wxlState, -2, type, name); // get the type and value ! GetTypeValue(wxlState, -1, type, value, &flag_type); int nRef = LUA_NOREF; *************** *** 268,277 **** lua_pop(L, 1); ! Add(new wxLuaDebugDataItem(name, type, value, source, nRef, nIndex)); count++; } ! // remove reference ! lua_pop(L, 1); } } --- 281,289 ---- lua_pop(L, 1); ! Add(new wxLuaDebugItem(name, type, value, wxT(""), nRef, nIndex, flag_type)); count++; } ! lua_pop(L, 1); // remove reference } } *************** *** 280,319 **** } ! int wxLuaDebugData::GetTypeValue(const wxLuaState& wxlState, int index, wxString& type, wxString& value) { wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); lua_State* L = wxlState.GetLuaState(); int l_type = lua_type(L, index); switch (l_type) { case LUA_TNONE: ! type = wxT("None"); value = wxEmptyString; break; case LUA_TNIL: ! type = wxT("Nil"); value = wxT("nil"); break; case LUA_TBOOLEAN: ! type = wxT("Boolean"); value = MakeBoolean(lua_toboolean(L, index)); break; case LUA_TNUMBER: ! type = wxT("Number"); value = MakeNumber(lua_tonumber(L, index)); break; case LUA_TSTRING: ! type = wxT("String"); value = lua2wx(lua_tostring(L, index)); break; case LUA_TTABLE: ! type = wxT("Table"); value = GetTableInfo(wxlState, index); break; --- 292,361 ---- } ! int wxLuaDebugData::GetTypeValue(const wxLuaState& wxlState, int index, wxString& type, wxString& value, int* flag_type_) { wxCHECK_MSG(wxlState.Ok(), 0, wxT("Invalid wxLuaState")); + + // try to use the wxString ref counting to reduce memory + static wxString s_typeStrings[WXLUA_DEBUGITEM_T_COUNT] = { + wxT("Unknown data type"), + wxT("None"), + wxT("Nil"), + wxT("Boolean"), + wxT("Light User Data"), + wxT("Number"), + wxT("String"), + wxT("Table"), + wxT("Lua Function"), + wxT("User Data"), + wxT("Thread"), + wxT("C Function") + }; + lua_State* L = wxlState.GetLuaState(); int l_type = lua_type(L, index); + int flag_type = WXLUA_DEBUGITEM_TUNKNOWN; switch (l_type) { case LUA_TNONE: ! type = s_typeStrings[WXLUA_DEBUGITEM_TNONE]; value = wxEmptyString; + flag_type = WXLUA_DEBUGITEM_TNONE; break; case LUA_TNIL: ! type = s_typeStrings[WXLUA_DEBUGITEM_TNIL]; value = wxT("nil"); + flag_type = WXLUA_DEBUGITEM_TNIL; break; case LUA_TBOOLEAN: ! type = s_typeStrings[WXLUA_DEBUGITEM_TBOOLEAN]; value = MakeBoolean(lua_toboolean(L, index)); + flag_type = WXLUA_DEBUGITEM_TBOOLEAN; + break; + + case LUA_TLIGHTUSERDATA: + type = s_typeStrings[WXLUA_DEBUGITEM_TLIGHTUSERDATA]; + value = GetUserDataInfo(wxlState, index, false); + flag_type = WXLUA_DEBUGITEM_TLIGHTUSERDATA; break; case LUA_TNUMBER: ! type = s_typeStrings[WXLUA_DEBUGITEM_TNUMBER]; value = MakeNumber(lua_tonumber(L, index)); + flag_type = WXLUA_DEBUGITEM_TNUMBER; break; case LUA_TSTRING: ! type = s_typeStrings[WXLUA_DEBUGITEM_TSTRING]; value = lua2wx(lua_tostring(L, index)); + flag_type = WXLUA_DEBUGITEM_TSTRING; break; case LUA_TTABLE: ! type = s_typeStrings[WXLUA_DEBUGITEM_TTABLE]; value = GetTableInfo(wxlState, index); + flag_type = WXLUA_DEBUGITEM_TTABLE; break; *************** *** 321,355 **** if (lua_iscfunction(L, index)) { ! type = wxT("C Function"); value.Printf(wxT("%p"), lua_tocfunction(L, index)); } else { ! type = wxT("Lua Function"); value.Printf(wxT("%p"), lua_topointer(L, index)); } break; case LUA_TUSERDATA: ! type = wxT("User Data"); value = GetUserDataInfo(wxlState, index, true); ! break; ! ! case LUA_TLIGHTUSERDATA: ! type = wxT("Light User Data"); ! value = GetUserDataInfo(wxlState, index, false); break; case LUA_TTHREAD: ! type = wxT("Thread"); value.Printf(wxT("%p"), lua_topointer(L, index)); break; default : ! type = wxT("Unknown data type"); value = wxEmptyString; break; } return l_type; } --- 363,399 ---- if (lua_iscfunction(L, index)) { ! type = s_typeStrings[WXLUA_DEBUGITEM_TCFUNCTION]; value.Printf(wxT("%p"), lua_tocfunction(L, index)); + flag_type = WXLUA_DEBUGITEM_TCFUNCTION; } else { ! type = s_typeStrings[WXLUA_DEBUGITEM_TFUNCTION]; value.Printf(wxT("%p"), lua_topointer(L, index)); + flag_type = WXLUA_DEBUGITEM_TFUNCTION; } break; case LUA_TUSERDATA: ! type = s_typeStrings[WXLUA_DEBUGITEM_TUSERDATA]; value = GetUserDataInfo(wxlState, index, true); ! flag_type = WXLUA_DEBUGITEM_TUSERDATA; break; case LUA_TTHREAD: ! type = s_typeStrings[WXLUA_DEBUGITEM_TTHREAD]; value.Printf(wxT("%p"), lua_topointer(L, index)); + flag_type = WXLUA_DEBUGITEM_TTHREAD; break; default : ! type = s_typeStrings[WXLUA_DEBUGITEM_TUNKNOWN]; value = wxEmptyString; + flag_type = WXLUA_DEBUGITEM_TUNKNOWN; break; } + if (flag_type_) *flag_type_ = flag_type; + return l_type; } *************** *** 359,368 **** long num = (long) dnum; if ((double) num == dnum) - { - if (num >= 0) - return wxString::Format(wxT("%lu (0x%lx)"), num, num); - return wxString::Format(wxT("%ld (0x%lx)"), num, num); - } return wxString::Format(wxT("%g"), dnum); --- 403,407 ---- *************** *** 438,471 **** { wxString message(!msg.IsEmpty() ? msg : m_msg); ! #if defined(__WXMSW__) ! wxString buf = wxString::Format(_("Stack state in '%s': in %u out %u\r\n"), message.c_str(), m_top, lua_gettop(m_luaState)); ! OutputDebugString(buf); ! #else //if defined(__WXGTK__) || defined(__WXMAC__) ! fprintf(stderr, "Stack state in '%s': in %u out %u\n", (const char *)wx2lua(msg), m_top, lua_gettop(m_luaState)); ! #endif } ! void wxLuaCheckStack::DumpGlobals(lua_State *L) { wxLuaStringToLongHashMap dumpList; lua_pushvalue(L, LUA_GLOBALSINDEX); ! DumpTable(L, lua_gettop(L), wxT("Globals"), dumpList, 0); lua_pop(L, 1); } ! void wxLuaCheckStack::DumpTable(lua_State *L, const wxString &name) { wxLuaStringToLongHashMap dumpList; lua_pushstring(L, wx2lua(name)); lua_gettable(L, LUA_GLOBALSINDEX); ! DumpTable(L, lua_gettop(L), name, dumpList, 0); lua_pop(L, 1); } ! void wxLuaCheckStack::DumpTable(lua_State *L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent) { wxLuaState wxlState(L); wxString indentStr; --- 477,516 ---- { wxString message(!msg.IsEmpty() ? msg : m_msg); + wxString s = wxString::Format(wxT("Stack state in '%s': starting top %d ending top %d\n"), + message.c_str(), m_top, lua_gettop(m_luaState)); ! OutputMsg(s); } ! void wxLuaCheckStack::DumpGlobals() { + wxCHECK_RET(m_luaState, wxT("Invalid lua_State")); + + lua_State* L = m_luaState; wxLuaStringToLongHashMap dumpList; lua_pushvalue(L, LUA_GLOBALSINDEX); ! DumpTable(lua_gettop(L), wxT("Globals"), dumpList, 0); lua_pop(L, 1); } ! void wxLuaCheckStack::DumpTable(const wxString &name) { + wxCHECK_RET(m_luaState, wxT("Invalid lua_State")); + + lua_State* L = m_luaState; wxLuaStringToLongHashMap dumpList; lua_pushstring(L, wx2lua(name)); lua_gettable(L, LUA_GLOBALSINDEX); ! DumpTable(lua_gettop(L), name, dumpList, 0); lua_pop(L, 1); } ! void wxLuaCheckStack::DumpTable(int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent) { + wxCHECK_RET(m_luaState, wxT("Invalid lua_State")); + + lua_State* L = m_luaState; wxLuaState wxlState(L); wxString indentStr; *************** *** 478,482 **** wxString title = wxString::Format(wxT("%sTable: %s"), indentStr.c_str(), tablename.c_str()); ! wxLogMessage(title); if (!indentStr.IsEmpty()) --- 523,527 ---- wxString title = wxString::Format(wxT("%sTable: %s"), indentStr.c_str(), tablename.c_str()); ! OutputMsg(title); if (!indentStr.IsEmpty()) *************** *** 498,502 **** valueType.c_str(), value.c_str()); ! wxLogMessage(info); if (dumpList.find(value) != dumpList.end()) --- 543,547 ---- valueType.c_str(), value.c_str()); ! OutputMsg(info); if (dumpList.find(value) != dumpList.end()) *************** *** 508,512 **** int tableIndex = lua_gettop(L); // lua_pushvalue(L, lua_gettop(L)); ! DumpTable(L, tableIndex, tname, dumpList, indent+1); } else --- 553,557 ---- int tableIndex = lua_gettop(L); // lua_pushvalue(L, lua_gettop(L)); ! DumpTable(tableIndex, tname, dumpList, indent+1); } else *************** *** 525,535 **** lua_pop(L, 1); ! wxLog::FlushActive(); } ! void wxLuaCheckStack::DumpStack(lua_State* L) { int i, count = lua_gettop(L); ! wxPrintf(wxT("wxLuaCheckStack::DumpStack(%ld) items %d\n"), (long)L, count); wxLuaState wxlState(L); --- 570,583 ---- lua_pop(L, 1); ! //wxLog::FlushActive(); } ! void wxLuaCheckStack::DumpStack() { + wxCHECK_RET(m_luaState, wxT("Invalid lua_State")); + + lua_State* L = m_luaState; int i, count = lua_gettop(L); ! OutputMsg(wxString... [truncated message content] |