From: John L. <jr...@us...> - 2007-06-16 06:21:51
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19284/wxLua/samples Modified Files: bindings.wx.lua editor.wx.lua unittest.wx.lua Removed Files: debug.wx.lua Log Message: Add back the wxTreeCtrl into the stack dialog, on left of listctrl so you get both for easier navigation. Added functions to the wxlua.XXX table to get info about the status of wxLua Use qsort and bsearch to find the class methods ~ %25 faster Make wxLuaDebugData not always create it's ref data so it can !Ok() Index: editor.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/editor.wx.lua,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** editor.wx.lua 14 Jun 2007 01:23:20 -0000 1.54 --- editor.wx.lua 16 Jun 2007 06:21:47 -0000 1.55 *************** *** 1721,1725 **** local id = editor:GetId() local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) ! local ret, errMsg, line_num = wx.CompileLuaScript(editorText, filePath) if menuBar:IsChecked(ID_CLEAROUTPUT) then ClearOutput() --- 1721,1725 ---- local id = editor:GetId() local filePath = MakeDebugFileName(editor, openDocuments[id].filePath) ! local ret, errMsg, line_num = wxlua.CompileLuaScript(editorText, filePath) if menuBar:IsChecked(ID_CLEAROUTPUT) then ClearOutput() --- debug.wx.lua DELETED --- Index: bindings.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/bindings.wx.lua,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** bindings.wx.lua 14 Jun 2007 23:59:49 -0000 1.9 --- bindings.wx.lua 16 Jun 2007 06:21:47 -0000 1.10 *************** *** 128,131 **** --- 128,136 ---- } + list_colors = { + ["purple"] = wx.wxColour("purple"), + } + + listColWidths = {} -- stored by "object_type" name *************** *** 144,147 **** --- 149,158 ---- -- ---------------------------------------------------------------------------- + -- Function to simulate var = cond ? a : b + -- ---------------------------------------------------------------------------- + + function iff(cond, a, b) if cond then return a else return b end end + + -- ---------------------------------------------------------------------------- -- Find the bindings installed into wxLua, tables that might have wxLuaBinding_ -- ---------------------------------------------------------------------------- *************** *** 159,232 **** -- ---------------------------------------------------------------------------- - -- Load all the wxWidgets wxClassInfo - -- ---------------------------------------------------------------------------- - function CreatewxClassInfoTable() - - -- create a table of tables of cols of the classname and baseclass names - -- if there is a baseclass2 then the returned table will have > 1 tables - local function GetBases(ci) - local c = ci - local t = {{}} - - while c do - table.insert(t[1], c:GetClassName()) - - if c:GetBaseClass2() then - --print(c:GetClassName(), "Has Base2", c:GetBaseClass2()) - - local baseTable2 = GetBases(c:GetBaseClass2()) - for i = 1, #baseTable2 do - -- insert back in the original info - for j = 1, #t do - table.insert(baseTable2[i], j, t[1][j]) - end - baseTable2[i][1] = baseTable2[i][1].." "..tostring(i) -- count # of base2s - table.insert(t, baseTable2[i]) - end - end - - c = c:GetBaseClass1() - end - - return t - end - - local t = { - {"..", ["icon"] = list_images.folder}, - ["col_labels"] = {"wxClassInfo::GetClassName()"}, - ["object_type"] = "All Classes" - } - - local ci = wx.wxClassInfo.GetFirst() - local max_cols = 1 - - while ci do - local baseTable = GetBases(ci) - for i = 1, #baseTable do - if max_cols < #baseTable[i] then max_cols = #baseTable[i] end - table.insert(t, baseTable[i]) - end - - ci = ci:GetNext() - end - - -- Fill remainder of items with "" string - for i = 1, #t do - for j = #t[i], max_cols do - table.insert(t[i], "") - end - end - - -- Create col labels - for i = 2, max_cols do - table.insert(t.col_labels, "Base Class "..tostring(i-1)) - end - - table.sort(t, function(t1, t2) return t1[1] < t2[1] end) - - return t - end - - -- ---------------------------------------------------------------------------- -- Save the current listctrl settings into the listColWidths table -- ---------------------------------------------------------------------------- --- 170,173 ---- *************** *** 262,265 **** --- 203,207 ---- local w = listCtrl:GetTextExtent(txt) if w > (listColWidths[data.object_type][col] or 0) - 25 then + if w > 400 then w = 400 end listColWidths[data.object_type][col] = w + 25 end *************** *** 303,312 **** li:SetData(i) -- key into the listData table for sorting ! if (d.icon) then ! li:SetImage(d.icon) ! end ! if (d.color) then ! li:SetTextColour(d.color) ! end lc_item = listCtrl:InsertItem(li) --- 245,250 ---- li:SetData(i) -- key into the listData table for sorting ! if (d.icon) then li:SetImage(d.icon) end ! if (d.color) then li:SetTextColour(d.color) end lc_item = listCtrl:InsertItem(li) *************** *** 386,394 **** -- Convert the argtags table into a readable string -- ---------------------------------------------------------------------------- ! function CreateArgTagsString(args_table) local arg_names = {} for j = 1, #args_table do ! table.insert(arg_names, wxlua.wxlua_typename(args_table[j])) end --- 324,342 ---- -- Convert the argtags table into a readable string -- ---------------------------------------------------------------------------- ! function CreateArgTagsString(args_table, wxlua_type) local arg_names = {} for j = 1, #args_table do ! local s = wxlua.wxlua_typename(args_table[j]) ! ! -- The first arg for a class member function is the self ! if (j == 1) and ! (bit.band(wxlua_type, wxlua.WXLUAMETHOD_CFUNCTION) == 0) and ! (bit.band(wxlua_type, wxlua.WXLUAMETHOD_CONSTRUCTOR) == 0) and ! (bit.band(wxlua_type, wxlua.WXLUAMETHOD_STATIC) == 0) then ! s = s.."(self)" ! end ! ! table.insert(arg_names, s) end *************** *** 402,406 **** local t = { {"..", ["icon"] = list_images.folder}, ! ["col_labels"] = { "name", "# methods", "wxClassInfo", "class tag", "Base Class Name", "# enums" }, ["object_type"] = "wxLuaBindClass" } --- 350,354 ---- local t = { {"..", ["icon"] = list_images.folder}, ! ["col_labels"] = { "Class Name", "# Methods", "wxClassInfo", "Class Tag", "Base Class Name", "# Enums" }, ["object_type"] = "wxLuaBindClass" } *************** *** 466,479 **** -- some sanity checks to make sure the bindings are working if (tbl[i].methods_n > 0) and (type(tbl[i].methods) ~= "table") then ! print(tbl[i].name, "is missing methods table") end if (tbl[i].baseclassName) and (type(tbl[i].baseclass) ~= "userdata") then ! print(tbl[i].name, "is missing baseclass userdata") end if (tbl[i].enums_n > 0) and (type(tbl[i].enums) ~= "table") then ! print(tbl[i].name, "is missing enums table") end - table.insert(t, item) end --- 414,426 ---- -- some sanity checks to make sure the bindings are working if (tbl[i].methods_n > 0) and (type(tbl[i].methods) ~= "table") then ! print(tbl[i].name, "is missing methods table, please report this.") end if (tbl[i].baseclassName) and (type(tbl[i].baseclass) ~= "userdata") then ! print(tbl[i].name, "is missing baseclass userdata, please report this.") end if (tbl[i].enums_n > 0) and (type(tbl[i].enums) ~= "table") then ! print(tbl[i].name, "is missing enums table, please report this.") end table.insert(t, item) end *************** *** 553,564 **** local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindDefine") ! for i = 2, #t do ! local n = t[i][2] ! t[i][3] = n -- store real number for sorting w/o hex ! -- these are often enums or flags, it's easier to see them as hex ! if n > 0 then ! t[i][2] = n..string.format(" (0x%X)", n) ! end end --- 500,511 ---- local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindDefine") ! t.col_numbers = {} ! t.col_numbers[2] = true ! -- these are often enums or flags, it's easier to see them as hex ! table.insert(t.col_labels, "hex") ! ! for i = 2, #t do ! t[i][3] = string.format("0x%X", t[i][2]) end *************** *** 581,584 **** --- 528,534 ---- local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindEvent") + t.col_numbers = {} + t.col_numbers[2] = true + -- Add the class tag name for the event for i = 2, #t do *************** *** 622,629 **** for i = 2, #t do local args = t[i][5] t[i][2] = CreatewxLuaMethod_TypeString(t[i][2]) - t[i][5] = CreateArgTagsString(args) -- swap these two - t[i][6] = table.concat(args, ", ") end --- 572,579 ---- for i = 2, #t do local args = t[i][5] + t[i][5] = CreateArgTagsString(args, t[i][2]) -- swap these two + t[i][6] = table.concat(args, ", ") t[i][2] = CreatewxLuaMethod_TypeString(t[i][2]) end *************** *** 685,693 **** local i2 = data2[col] ! if (data.object_type == "wxLuaBindDefine") and (col == 2) then ! -- sort on the real numbers, not the strings w/ hex ! i1 = data1[3] ! i2 = data2[3] ! elseif data.col_numbers[col] then -- sort on the real numbers, but treat "" as lower if (i1 == "") and (i2 == "") then --- 635,639 ---- local i2 = data2[col] ! if data.col_numbers and data.col_numbers[col] then -- sort on the real numbers, but treat "" as lower if (i1 == "") and (i2 == "") then *************** *** 757,766 **** -- ---------------------------------------------------------------------------- function OnListItemActivated(event) ! local index = event:GetIndex() -- note: 0 based, lua tables start at 1 ! local data_index = event:GetData() ! local itemText = listCtrl:GetItemText(index) local data = listData[list_level] -- ----------------------------------------------------------------------- -- Find what column we're in --- 703,715 ---- -- ---------------------------------------------------------------------------- function OnListItemActivated(event) ! local index = event:GetIndex() -- note: 0 based, lua tables start at 1 ! local data_index = event:GetData() -- this is the table index ! local itemText = listCtrl:GetItemText(index) local data = listData[list_level] + listData[list_level].list_item = index -- last clicked + SaveListColWidths(list_level) -- remember user's col widths + -- ----------------------------------------------------------------------- -- Find what column we're in *************** *** 792,798 **** end ! listData[list_level].list_item = index ! SaveListColWidths(list_level) -- remember user's col widths ! if (itemText == "..") then list_level = list_level - 1 --- 741,745 ---- end ! -- Handle the different lists we may show if (itemText == "..") then list_level = list_level - 1 *************** *** 800,826 **** elseif (list_level == 1) then if itemText == "wxLua Types" then - local t = CreatewxLuaTypeTable() - list_level = list_level + 1 ! listData[list_level] = t GotoBindingLevel(listCtrl, list_level) elseif itemText == "All wxLua Classes" then - local t = CreateAllClassesTable() - list_level = list_level + 1 ! listData[list_level] = t GotoBindingLevel(listCtrl, list_level) elseif itemText == "All wxWidgets wxClassInfo" then - local t = CreatewxClassInfoTable() - list_level = list_level + 1 ! listData[list_level] = t GotoBindingLevel(listCtrl, list_level) - elseif itemText == "Overloaded Baseclass Functions" then - local t = CreateOverloadedBasecassFunctionsTable() - list_level = list_level + 1 ! listData[list_level] = t GotoBindingLevel(listCtrl, list_level) else --- 747,764 ---- elseif (list_level == 1) then if itemText == "wxLua Types" then list_level = list_level + 1 ! listData[list_level] = CreatewxLuaTypeTable() GotoBindingLevel(listCtrl, list_level) elseif itemText == "All wxLua Classes" then list_level = list_level + 1 ! listData[list_level] = CreateAllClassesTable() GotoBindingLevel(listCtrl, list_level) elseif itemText == "All wxWidgets wxClassInfo" then list_level = list_level + 1 ! listData[list_level] = CreatewxClassInfoTable() GotoBindingLevel(listCtrl, list_level) elseif itemText == "Overloaded Baseclass Functions" then list_level = list_level + 1 ! listData[list_level] = CreateOverloadedBasecassFunctionsTable() GotoBindingLevel(listCtrl, list_level) else *************** *** 851,855 **** elseif (list_level == 2) then local binding = listData[2].binding - local t = nil --- 789,792 ---- *************** *** 873,877 **** GotoBindingLevel(listCtrl, list_level) end ! elseif (data_index > 1) and listData[list_level].object_type == "wxLuaBindClass" then local t = nil --- 810,814 ---- GotoBindingLevel(listCtrl, list_level) end ! elseif (data_index > 1) and data.object_type == "wxLuaBindClass" then local t = nil *************** *** 880,890 **** if frame:GetMenuBar():IsChecked(ID_VIEW_BASECLASS_FUNCTIONS) then ! local c = data[data_index][5] while type(c) == "userdata" do local tt = CreatewxLuaBindMethod(c.methods, c.name) for i = 2, #tt do -- skip ".." if not (string.find(tt[i][2], "Constructor", 1, 1) or ! string.find(t[i][1], "Delete", 1, 1) or ! string.find(t[i][1], "::"..c.name, 1, 1)) then table.insert(t, tt[i]) end --- 817,827 ---- if frame:GetMenuBar():IsChecked(ID_VIEW_BASECLASS_FUNCTIONS) then ! local c = data[data_index].data[5] while type(c) == "userdata" do local tt = CreatewxLuaBindMethod(c.methods, c.name) for i = 2, #tt do -- skip ".." if not (string.find(tt[i][2], "Constructor", 1, 1) or ! string.find(t[i][1], "delete", 1, 1)) then ! --string.find(t[i][1], "::"..c.name, 1, 1)) then table.insert(t, tt[i]) end *************** *** 906,910 **** GotoBindingLevel(listCtrl, list_level) end ! elseif (data_index > 1) and listData[list_level].object_type == "wxLuaBindMethod" then local t = nil --- 843,847 ---- GotoBindingLevel(listCtrl, list_level) end ! elseif (data_index > 1) and data.object_type == "wxLuaBindMethod" then local t = nil *************** *** 962,984 **** "WXLUAARG_Number", "WXLUAARG_String", ! "WXLUAARG_LuaTable", ! "WXLUAARG_LuaFunction", "WXLUAARG_UserData", ! "WXLUAARG_LuaThread", "WXLUAARG_Integer" } for i = 1, #wxltype_names do local wxltype = wxlua[wxltype_names[i]] ! local row = { wxltype_names[i].." "..tostring(wxltype) } ! for j = 2, #t.col_labels do ! local ltype = wxlua[lua_types[j-1]] local ok = wxlua.wxlua_iswxluatype(ltype, wxltype) ! if ok == 1 then ok = "X" end ! if ok == 0 then ok = "" end ! if ok == -1 then ok = "?" end -- shouldn't happen! ! table.insert(row, ok) end ! table.insert(t, row) end --- 899,920 ---- "WXLUAARG_Number", "WXLUAARG_String", ! "WXLUAARG_Table", ! "WXLUAARG_Function", "WXLUAARG_UserData", ! "WXLUAARG_Thread", "WXLUAARG_Integer" } + local tostr = { [1] = "X", [0] = "", [-1] = "?" } + for i = 1, #wxltype_names do local wxltype = wxlua[wxltype_names[i]] ! local item = { wxltype_names[i].." "..tostring(wxltype) } ! for j = 1, #lua_types do ! local ltype = wxlua[lua_types[j]] local ok = wxlua.wxlua_iswxluatype(ltype, wxltype) ! table.insert(item, tostr[ok]) end ! table.insert(t, item) end *************** *** 1002,1005 **** --- 938,946 ---- ["wxDCBase"] = 1, ["wxFileDialogBase"] = 1, + ["wxGenericDirDialog"] = 1, + ["wxGenericFileDialog"] = 1, + ["wxGenericImageList"] = 1, + ["wxGenericListCtrl"] = 1, + ["wxGenericTreeCtrl"] = 1, ["wxPrinterBase"] = 1, ["wxPrintPreviewBase"] = 1, *************** *** 1019,1022 **** --- 960,974 ---- } + -- These notes for classes that where the classinfo doesn't match + -- the classname is the one that wxLua uses, not the one wxWidgets uses + local classinfoNotes = { + ["wxAutoBufferedPaintDC"] = "(Platform dep. baseclass, wxDC is ok)", + ["wxHelpController"] = "(Platform dep. typedef by wxWidgets)", + ["wxLuaDebuggerServer"] = "(Platform dep. typedef by wxLua)", + ["wxMemoryDC"] = "(Platform dep. baseclass, wxDC is ok)", + ["wxPaintDC"] = "(Platform dep. baseclass, wxWindowDC is ok)", + ["wxScreenDC"] = "(Platform dep. baseclass, wxDC is ok)", + } + for b = 1, #bindingList do local binding = _G *************** *** 1061,1066 **** while ci do - local item - -- we don't bind some classes since we wouldn't need them if unwrappedBaseClasses[ci:GetClassName()] then --- 1013,1016 ---- *************** *** 1069,1075 **** table.insert(c_table2, c_table[#c_table2+1].." - No wxClassInfo") table.insert(c_table2, ci:GetClassName()) else table.insert(c_table2, ci:GetClassName()) ! if (c_table[#c_table2] ~= c_table2[#c_table2]) then c_table2.color = wx.wxRED end --- 1019,1030 ---- table.insert(c_table2, c_table[#c_table2+1].." - No wxClassInfo") table.insert(c_table2, ci:GetClassName()) + elseif c_table[#c_table2+1] and classinfoNotes[c_table[#c_table2+1]] then + c_table[#c_table2+1] = c_table[#c_table2+1]..classinfoNotes[c_table[#c_table2+1]] + table.insert(c_table2, ci:GetClassName()) + c_table2.color = list_colors.purple else table.insert(c_table2, ci:GetClassName()) ! if ((c_table[#c_table2] ~= c_table2[#c_table2])) and ! (c_table2.color == nil) then c_table2.color = wx.wxRED end *************** *** 1096,1100 **** end ! -- Put strings where there is no base class for i = 1, #t do for j = 1, max_cols do --- 1051,1055 ---- end ! -- Put "" strings where there is no base class for i = 1, #t do for j = 1, max_cols do *************** *** 1106,1109 **** --- 1061,1153 ---- end + -- ---------------------------------------------------------------------------- + -- Load all the wxWidgets wxClassInfo + -- ---------------------------------------------------------------------------- + function CreatewxClassInfoTable() + + -- gather up all of wxLua wrapped classes + local wxluaClasses = {} + + for b = 1, #bindingList do + local binding = _G + for i = 1, #bindingList[b] do + binding = binding[bindingList[b][i]] + end + + local classTable = binding.GetClassArray + + for i = 1, #classTable do + wxluaClasses[classTable[i].name] = true + end + end + + -- create a table of tables of cols of the classname and baseclass names + -- if there is a baseclass2 then the returned table will have > 1 tables + local function GetBases(ci) + local c = ci + local t = {{}} + + while c do + table.insert(t[1], c:GetClassName()) + + if c:GetBaseClass2() then + --print(c:GetClassName(), "Has Base2", c:GetBaseClass2()) + + local baseTable2 = GetBases(c:GetBaseClass2()) + for i = 1, #baseTable2 do + -- insert back in the original info + for j = 1, #t do + table.insert(baseTable2[i], j, t[1][j]) + end + baseTable2[i][1] = baseTable2[i][1].." (Multiple base classes "..tostring(i)..")" -- count # of base2s + table.insert(t, baseTable2[i]) + end + end + + c = c:GetBaseClass1() + end + + return t + end + + local t = { + {"..", ["icon"] = list_images.folder}, + ["col_labels"] = {"wxClassInfo::GetClassName() (wxLua wraps blue)"}, + ["object_type"] = "All wxWidgets wxClassInfo" + } + + local ci = wx.wxClassInfo.GetFirst() + local max_cols = 1 + + while ci do + local baseTable = GetBases(ci) + for i = 1, #baseTable do + if wxluaClasses[baseTable[i][1]] then + baseTable[i].color = wx.wxBLUE + end + + if max_cols < #baseTable[i] then max_cols = #baseTable[i] end + table.insert(t, baseTable[i]) + end + + ci = ci:GetNext() + end + + -- Fill remainder of items with "" string + for i = 1, #t do + for j = #t[i], max_cols do + table.insert(t[i], "") + end + end + + -- Create col labels + for i = 2, max_cols do + table.insert(t.col_labels, "Base Class "..tostring(i-1)) + end + + table.sort(t, function(t1, t2) return t1[1] < t2[1] end) + + return t + end -- ---------------------------------------------------------------------------- *************** *** 1133,1156 **** for j = 1, classTable[i].methods_n do local m = methods[j] ! local m_table = {m.class_name, m.name} ! ! local funcs = m.funcs ! local s = "" ! for f = 1, m.funcs_n do ! s = s.."("..CreateArgTagsString(funcs[f].argtags)..") " ! end ! table.insert(m_table, s) ! ! while m.basemethod do ! m = m.basemethod ! table.insert(m_table, m.class_name) local funcs = m.funcs local s = "" for f = 1, m.funcs_n do ! s = s.."("..CreateArgTagsString(funcs[f].argtags)..") " end table.insert(m_table, s) end if #m_table > 3 then if max_cols < #m_table then max_cols = #m_table end --- 1177,1194 ---- for j = 1, classTable[i].methods_n do local m = methods[j] ! local m_table = {m.name} + while m do local funcs = m.funcs local s = "" for f = 1, m.funcs_n do ! s = s.."("..CreateArgTagsString(funcs[f].argtags, funcs[f].type)..") " end + + table.insert(m_table, m.class_name) table.insert(m_table, s) + m = m.basemethod end + if #m_table > 3 then if max_cols < #m_table then max_cols = #m_table end *************** *** 1211,1218 **** frame:Connect(ID_STACK_DIALOG, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! local LocalNumberVariable = 2 ! local LocalStringVariable = "Hello" ! wxlua.LuaStackDialog() end ) --- 1249,1263 ---- frame:Connect(ID_STACK_DIALOG, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! local LocalVar1_InEventFn = 1 ! local LocalVar2_InEventFn = "Two" ! local function LocalFunction(var) ! local LocalVar1_InLocalFuncInEventFn = 3 ! local LocalVar2_InLocalFuncInInEventFn = "Four" ! ! wxlua.LuaStackDialog() ! end ! ! LocalFunction(LocalStringVariable) end ) Index: unittest.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/unittest.wx.lua,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** unittest.wx.lua 14 Jun 2007 05:02:49 -0000 1.12 --- unittest.wx.lua 16 Jun 2007 06:21:47 -0000 1.13 *************** *** 256,259 **** --- 256,263 ---- PrintOk(b:GetX() == 1, "Test wxLuaObject::GetObject(userdata).") + a = function(txt) return txt.."!" end + o = wxlua.wxLuaObject(a); b = o:GetObject() + PrintOk((a == b) and (b("Hello") == "Hello!"), "Test wxLuaObject::GetObject(function).") + -- --------------------------------------------------------------------------- print("\nTest the bit library.\n") |