From: John L. <jr...@us...> - 2007-06-13 00:09:09
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10172/wxLua/samples Modified Files: bindings.wx.lua unittest.wx.lua Log Message: Add new flag for wxLuaBindMethod WXLUAMETHOD_DELETE to know if this is our special delete function. Do not treat the delete function as if it was overloaded from base class Fix MSVC warnings about comparing ints and enums in wxlbind.cpp Add "class" to get class from wxLuaBinding_XXX in lua, also check for null for class_name Add bitlib from Reuben Thomas to wxlstate.cpp, maybe not the best place, but it's small Add code for bindings.wx.lua to check base classes and also functions overloading base class functions Add more unittest.wx.lua code to verify bindings Index: bindings.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/bindings.wx.lua,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** bindings.wx.lua 12 Jun 2007 00:08:42 -0000 1.4 --- bindings.wx.lua 13 Jun 2007 00:09:04 -0000 1.5 *************** *** 134,137 **** --- 134,150 ---- -- ["list_item"] = last selected list item or nil if not set + bindingList = {} -- Table of {"name space", "wxLuaBinding_XXX function"} + + -- ---------------------------------------------------------------------------- + -- Find the bindings installed into wxLua + -- ---------------------------------------------------------------------------- + + for k, v in pairs(wx) do + if string.find(k, "wxLuaBinding_", 1, 1) then + table.insert(bindingList, {"wx", k}) + end + end + + -- ---------------------------------------------------------------------------- -- Save the current listctrl settings into the listColWidths table *************** *** 263,267 **** -- Convert the wxLuaMethod_Type enum into a readable string -- ---------------------------------------------------------------------------- ! function ConvertwxLuaMethod_Type(t_) local s = {} local t = t_ --- 276,280 ---- -- Convert the wxLuaMethod_Type enum into a readable string -- ---------------------------------------------------------------------------- ! function CreatewxLuaMethod_TypeString(t_) local s = {} local t = t_ *************** *** 277,280 **** --- 290,294 ---- -- subtract values from high to low value t = HasBit(t, wx.WXLUAMETHOD_OVERLOAD_BASE, nil, nil) -- nobody should care about this + t = HasBit(t, wx.WXLUAMETHOD_DELETE, s, "Delete") t = HasBit(t, wx.WXLUAMETHOD_OVERLOAD, s, "Overload") t = HasBit(t, wx.WXLUAMETHOD_STATIC, s, "Static") *************** *** 294,297 **** --- 308,325 ---- -- ---------------------------------------------------------------------------- + -- 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, wx.wxlua_typename(args_table[j])) + end + + return table.concat(arg_names, ", ") + end + + -- ---------------------------------------------------------------------------- -- Create tables from the different binding structs type -- ---------------------------------------------------------------------------- *************** *** 343,347 **** i = i + 1 ! t[i][2] = ConvertwxLuaMethod_Type(t[i][2]) -- Add in the CFuncs --- 371,375 ---- i = i + 1 ! t[i][2] = CreatewxLuaMethod_TypeString(t[i][2]) -- Add in the CFuncs *************** *** 356,360 **** local cfunc_t = CreatewxLuaBindCFunc(t[i][3]) for j = 2, #cfunc_t do ! table.insert(t, i+j-1, {t[i][1].." "..j-1, cfunc_t[j][2], cfunc_t[j][1], "", "", cfunc_t[j][3], cfunc_t[j][4], cfunc_t[j][5], cfunc_t[j][6]}) end --- 384,390 ---- local cfunc_t = CreatewxLuaBindCFunc(t[i][3]) for j = 2, #cfunc_t do ! local cft = {t[i][1].." "..j-1, cfunc_t[j][2], cfunc_t[j][1], "", "", cfunc_t[j][3], cfunc_t[j][4], cfunc_t[j][5], cfunc_t[j][6]} ! if string.find(cfunc_t[j][2], "Overload", 1, 1) then cft.color = wx.wxGREEN end ! table.insert(t, i+j-1, cft) end *************** *** 418,432 **** t.col_labels[6] ="argtags" -- we don't want to show the table, just show the values for i = 2, #t do local args = t[i][5] - local arg_names = {} ! for j = 1, #args do ! table.insert(arg_names, wx.wxlua_typename(args[j])) ! end ! ! t[i][2] = ConvertwxLuaMethod_Type(t[i][2]) ! t[i][5] = table.concat(arg_names, ", ") -- swap these two t[i][6] = table.concat(args, ", ") end --- 448,458 ---- t.col_labels[6] ="argtags" + -- we don't want to show the table, just show the values 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 *************** *** 464,477 **** function OnListColClicked(event) local col = event:GetColumn() ! if not listData[list_level].col_sorted then ! listData[list_level].col_sorted = {} end ! local sorted = listData[list_level].col_sorted[col+1] local function SortListItems(item1, item2, col) ! local data1 = listData[list_level][item1] ! local data2 = listData[list_level][item2] if data1[1] == ".." then return -1 end --- 490,508 ---- function OnListColClicked(event) local col = event:GetColumn() + SortListItems(col) + end ! function SortListItems(col) ! local data = listData[list_level] ! ! if not data.col_sorted then ! data.col_sorted = {} end ! local sorted = data.col_sorted[col+1] local function SortListItems(item1, item2, col) ! local data1 = data[item1] ! local data2 = data[item2] if data1[1] == ".." then return -1 end *************** *** 481,491 **** local i2 = data2[col] ! if (listData[list_level].object_type == "wxLuaBindDefine") and (col == 2) then -- sort on the real numbers, not the strings w/ hex i1 = data1[3] i2 = data2[3] ! elseif ((listData[list_level].object_type == "wxLuaBindClass") and ((col == 3) or (col == 5) or (col == 9))) or ! ((listData[list_level].object_type == "wxLuaBindMethod") and ((col == 4) or (col == 6) or (col == 7))) or ! ((listData[list_level].object_type == "wxLuaBindCFunc") and ((col == 3) or (col == 4))) then -- sort on the real numbers, but treat "" as lower if (i1 == "") and (i2 == "") then --- 512,522 ---- 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.object_type == "wxLuaBindClass") and ((col == 3) or (col == 5) or (col == 9))) or ! ((data.object_type == "wxLuaBindMethod") and ((col == 4) or (col == 6) or (col == 7))) or ! ((data.object_type == "wxLuaBindCFunc") and ((col == 3) or (col == 4))) then -- sort on the real numbers, but treat "" as lower if (i1 == "") and (i2 == "") then *************** *** 517,520 **** --- 548,567 ---- listCtrl:SortItems(SortListItems, col+1) + -- now make the table of data match what's in the listctrl so when you + -- go up a level it'll stay sorted the same way + -- Note: it seems faster to let the listctrl sort and then match the lua table + -- rather than sort table, clear listctrl, and add it back. + local t = {} + for i = 1, listCtrl:GetItemCount() do + local d = listCtrl:GetItemData(i-1) -- old table indexes + table.insert(t, data[d]) -- table with listctrl order + end + + for i = 1, #t do + listData[list_level][i] = t[i] -- update original table + listCtrl:SetItemData(i-1, i) -- fix itemdata to match table indexes + end + + for c = 1, listCtrl:GetColumnCount() do listCtrl:SetColumnImage(c-1, -1) *************** *** 522,529 **** if not sorted then ! listData[list_level].col_sorted[col+1] = true listCtrl:SetColumnImage(col, img_sort_dn) else ! listData[list_level].col_sorted[col+1] = false listCtrl:SetColumnImage(col, img_sort_up) end --- 569,576 ---- if not sorted then ! data.col_sorted[col+1] = true listCtrl:SetColumnImage(col, img_sort_dn) else ! data.col_sorted[col+1] = false listCtrl:SetColumnImage(col, img_sort_up) end *************** *** 612,615 **** --- 659,794 ---- listData[list_level] = t GotoBindingLevel(listCtrl, list_level) + elseif itemText == "Base Classes" then + local t = { + {"..", ["icon"] = img_folder}, + ["col_labels"] = {"Class Name - wxClassInfo Name (wxClassInfo Base Name)"}, + ["object_type"] = "Base Classes" + } + + local max_cols = 1 + + local function GetClassInfoStr(ci) + local s = "" + if type(ci) == "userdata" then + s = s.." - "..ci:GetClassName() + local b1 = ci:GetBaseClassName1() + local b2 = ci:GetBaseClassName2() + + if (string.len(b1) > 0) then + s = s.." ("..b1..")" + end + if (string.len(b2) > 0) then + s = s.."("..b2..")" + end + end + return s + end + + for b = 1, #bindingList do + local binding = _G + for i = 1, #bindingList[b] do + binding = binding[bindingList[b][i]] + end + + local t1 = binding.GetClassArray + + for i = 1, #t1 do + local c = t1[i] + local c_table = {c.name..GetClassInfoStr(c.classInfo)} + + -- traverse through the base classes + local bc = c.baseclass + while bc do + table.insert(c_table, bc.name..GetClassInfoStr(bc.classInfo)) + bc = bc.baseclass + end + + if max_cols < #c_table then max_cols = #c_table end + table.insert(t, c_table) + end + end + + -- Set the col labels after counting them + for i = 2, max_cols do + t.col_labels[i] = "Base class "..tostring(i-1) + end + + -- Put strings where there is no base class + for i = 1, #t do + for j = 1, max_cols do + if t[i][j] == nil then t[i][j] = "" end + end + end + + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) + elseif itemText == "Overloaded Baseclass Functions" then + local t = { + {"..", ["icon"] = img_folder}, + ["col_labels"] = {"Class Name", "Function Name", "Args"}, + ["object_type"] = "Overloaded Baseclass Functions" + } + + local max_cols = 2 + + for b = 1, #bindingList do + local binding = _G + for i = 1, #bindingList[b] do + binding = binding[bindingList[b][i]] + end + + local t1 = binding.GetClassArray + + for i = 1, #t1 do + local methods = t1[i].methods + + -- some classes don't have methods, wxBestHelpController for example + for j = 1, t1[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 + table.insert(t, m_table) + end + end + end + end + + -- Set the col labels after counting them + for i = 4, max_cols, 2 do + t.col_labels[i] = "Base Class" + t.col_labels[i+1] = "Args" + end + + -- Put strings where there is no base class + for i = 1, #t do + for j = 1, max_cols do + if t[i][j] == nil then t[i][j] = "" end + end + end + + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) else local binding = _G *************** *** 774,785 **** list_level = 1 listData[1] = { ! {"wxLua Types", "Compare Lua's type to wxLua's type", ["icon"] = img_folder }, ! {"wx", "wxLuaBinding_wx", ["icon"] = img_folder }, ! {"wx", "wxLuaBinding_wxstc", ["icon"] = img_folder }, ! {"wx", "wxLuaBinding_wxluasocket", ["icon"] = img_folder }, ["col_labels"] = { "Lua Namespace", "Binding userdata" }, ["object_type"] = " " } GotoBindingLevel(listCtrl, 1) --- 953,970 ---- list_level = 1 listData[1] = { ! {"wxLua Types", "Compare Lua's type to wxLua's type", ["icon"] = img_folder }, ! {"Base Classes", "See base classes for all binding classes", ["icon"] = img_folder }, ! {"Overloaded Baseclass Functions", "See all functions that also have a baseclass function", ["icon"] = img_folder }, ! ["col_labels"] = { "Lua Namespace", "Binding userdata" }, ["object_type"] = " " } + + -- Add the binding that are installed {"wx", "wxLuaBinding_wx", ["icon"] = img_folder }, + for i = 1, #bindingList do + table.insert(listData[1], {bindingList[i][1], bindingList[i][2], ["icon"] = img_folder }) + end + GotoBindingLevel(listCtrl, 1) Index: unittest.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/unittest.wx.lua,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** unittest.wx.lua 12 Jun 2007 00:08:42 -0000 1.10 --- unittest.wx.lua 13 Jun 2007 00:09:04 -0000 1.11 *************** *** 62,65 **** --- 62,67 ---- PrintOk(a == wx.wxFile.read and a == 0, "Test %enum wxFile::OpenMode::read == 0") + PrintOk(wx.wxFTP.ASCII ~= nil, "Test class %enum wxFTP::ASCII is bound as wx.wxFTP.ASCII.") + a = wx.wxEVT_NULL PrintOk(a == wx.wxEVT_NULL, "Test %define_event wxEVT_NULL == -1") *************** *** 75,78 **** --- 77,84 ---- PrintOk(a:FindOrCreatePen(wx.wxRED, 1, wx.wxSOLID):Ok(), "Test %define_pointer wxThePenList:FindOrCreatePen(wx.wxRED, 1, wx.wxSOLID) is Ok()") + -- --------------------------------------------------------------------------- + print("\nTest some automatic overload binding functions.\n") + -- --------------------------------------------------------------------------- + a = wx.wxString("Hello") PrintOk(a:GetData() == "Hello", "Test automatic overload of wxString(\"lua string\")") *************** *** 108,117 **** -- --------------------------------------------------------------------------- ! print("\nTest some binding class functions.\n") -- --------------------------------------------------------------------------- pt = wx.wxPoint(1, 2) ! PrintOk(pt:GetX() == 1, "%rename %member using wxPoint:GetX()") ! PrintOk(pt.x == 1, "%rename %member using wxPoint.x") pt2 = wx.wxPoint(pt) --- 114,124 ---- -- --------------------------------------------------------------------------- ! print("\nTest some %member binding class functions.\n") -- --------------------------------------------------------------------------- pt = wx.wxPoint(1, 2) ! PrintOk(pt:GetX() == 1, "%rename %member using wxPoint:GetX(), member variable functions") ! PrintOk(pt.x == 1, "%rename %member using wxPoint.x, member variable properties work.") ! PrintOk(pt.X == 1, "%rename %member using wxPoint.X, automatic properties work.") pt2 = wx.wxPoint(pt) *************** *** 126,129 **** --- 133,144 ---- pt:SetX(20) PrintOk(pt.x == 20, "%rename %member using wxPoint:SetX(20); wxPoint.x") + pt.SetX(pt, 30) + PrintOk(pt.x == 30, "%rename %member using wxPoint.SetX(self, 30); wxPoint.x") + pt.X = 40 + PrintOk(pt.X == 40, "%rename %member using wxPoint.X = 40; wxPoint.x") + + -- --------------------------------------------------------------------------- + print("\nTest some binding class functions.\n") + -- --------------------------------------------------------------------------- -- Call functions with user data *************** *** 147,153 **** -- Test static functions and calling them ! fname = 'a321.123X!x!' f = wx.wxFileName(fname) PrintOk(f.GetCwd() == wx.wxFileName.GetCwd(), "Calling static wxString wxFileName::GetCwd(), as static member and static global.") -- Test overloaded static and non static functions --- 162,169 ---- -- Test static functions and calling them ! fname = 'a321.123X!x!' -- should not exist f = wx.wxFileName(fname) PrintOk(f.GetCwd() == wx.wxFileName.GetCwd(), "Calling static wxString wxFileName::GetCwd(), as static member and static global.") + PrintOk(f.GetCwd() == wx.wxGetCwd(), "Calling static wxString wxFileName::GetCwd() == wx.wxGetCwd().") -- Test overloaded static and non static functions *************** *** 158,163 **** PrintOk(f(5,5):Ok(), "Calling wx.wxImage.new(5,5) function as constructor.") ! -- Test class member enums to see if they're bound ! PrintOk(wx.wxFTP.ASCII ~= nil, "See if class enum wxFTP::ASCII enum is bound as wx.wxFTP.ASCII.") -- --------------------------------------------------------------------------- --- 174,185 ---- PrintOk(f(5,5):Ok(), "Calling wx.wxImage.new(5,5) function as constructor.") ! -- Test calling a baseclass function a few levels deep ! a = wx.wxStdDialogButtonSizer(); -- base is wxBoxSizer whose base is wxSizer ! a:SetMinSize(1, 2) -- this should also work ! PrintOk(a:GetMinSize():GetWidth() == 1, "Calling wx.wxStdDialogButtonSizer[base func wxBoxSizer->wxSizer]::GetMinSize().") ! PrintOk(a:GetOrientation() == wx.wxHORIZONTAL, "Calling wx.wxStdDialogButtonSizer[base func wxBoxSizer]::GetOrientation().") ! PrintOk(a:GetCancelButton() == nil, "Calling wx.wxStdDialogButtonSizer::GetCancelButton().") -- not a great test ! b = wx.wxButton(); b:SetName("Hello"); a:SetCancelButton(b) ! PrintOk(a:GetCancelButton():GetName() == "Hello", "Calling wx.wxStdDialogButtonSizer::GetCancelButton() after setting it with a button.") -- --------------------------------------------------------------------------- *************** *** 196,202 **** PrintOk(a:TestVirtualFunctionBinding("Hello") == "Hello-Base-Lua", "Test wxLuaPrintout::TestVirtualFunctionBinding overriding it and calling base.") ! print("\n") print("Tests run : "..tostring(tests_run)..", Tests that failed : "..tostring(failed_tests)..".\n") \ No newline at end of file --- 218,237 ---- PrintOk(a:TestVirtualFunctionBinding("Hello") == "Hello-Base-Lua", "Test wxLuaPrintout::TestVirtualFunctionBinding overriding it and calling base.") + -- --------------------------------------------------------------------------- + print("\nTest the bit library.\n") + -- --------------------------------------------------------------------------- + PrintOk(bit.bnot(0) == -1, "Test bit library bit.bnot.") + PrintOk(bit.band(0x1, 0x3, 0x5) == 1, "Test bit library bit.band.") + PrintOk(bit.bor(0x1, 0x3, 0x5) == 7, "Test bit library bit.bor.") + PrintOk(bit.bxor(0x1, 0x1, 0x3, 0x5) == 6, "Test bit library bit.bxor.") + PrintOk(bit.lshift(0x1, 1) == 2, "Test bit library bit.lshift.") + PrintOk(bit.rshift(0x2, 1) == 1, "Test bit library bit.rshift.") + PrintOk(bit.arshift(-2, 1) == -1, "Test bit library bit.arshift.") -- note this preserves sign + PrintOk(bit.mod(7, 2) == 1, "Test bit library bit.mod.") ! -- --------------------------------------------------------------------------- ! print("\n\nResults.\n") ! -- --------------------------------------------------------------------------- print("Tests run : "..tostring(tests_run)..", Tests that failed : "..tostring(failed_tests)..".\n") \ No newline at end of file |