You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(191) |
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(238) |
Dec
(68) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(104) |
Feb
(518) |
Mar
(302) |
Apr
(211) |
May
(311) |
Jun
(55) |
Jul
(6) |
Aug
(35) |
Sep
(76) |
Oct
(50) |
Nov
(37) |
Dec
(340) |
2007 |
Jan
(23) |
Feb
(107) |
Mar
(98) |
Apr
(60) |
May
(136) |
Jun
(371) |
Jul
(175) |
Aug
(74) |
Sep
(3) |
Oct
(2) |
Nov
(53) |
Dec
(129) |
2008 |
Jan
(337) |
Feb
(23) |
Mar
(18) |
Apr
(4) |
May
(3) |
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
(33) |
Nov
|
Dec
(26) |
2009 |
Jan
(4) |
Feb
(1) |
Mar
(15) |
Apr
|
May
(35) |
Jun
(11) |
Jul
|
Aug
|
Sep
(19) |
Oct
(26) |
Nov
(11) |
Dec
(11) |
2010 |
Jan
(4) |
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(8) |
Sep
|
Oct
|
Nov
(8) |
Dec
(7) |
2011 |
Jan
|
Feb
|
Mar
(4) |
Apr
(8) |
May
(5) |
Jun
(8) |
Jul
(1) |
Aug
|
Sep
|
Oct
(5) |
Nov
(13) |
Dec
|
From: John L. <jr...@us...> - 2006-06-06 21:04:09
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29787/wxLua/samples Modified Files: coroutine.wx.lua Log Message: fix sizing of textctrl for MSW not making only child win fill a dialog Index: coroutine.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/coroutine.wx.lua,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** coroutine.wx.lua 6 Jun 2006 05:14:32 -0000 1.1 --- coroutine.wx.lua 6 Jun 2006 21:03:54 -0000 1.2 *************** *** 48,51 **** --- 48,54 ---- wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxTE_MULTILINE + wx.wxTE_READONLY) + local mainSizer = wx.wxBoxSizer(wx.wxVERTICAL) + mainSizer:AddWindow(o.label, 1, wx.wxGROW) + o.dialog:SetSizer(mainSizer) -- Handle idle events: run the coroutine's next "step" |
From: John L. <jr...@us...> - 2006-06-06 05:14:39
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8826/wxLua/modules/wxlua/src Modified Files: wxlbind.cpp wxlstate.cpp Log Message: add coroutine.wx.lua sample and fix coroutines after breaking it from require code Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** wxlstate.cpp 30 May 2006 22:56:29 -0000 1.71 --- wxlstate.cpp 6 Jun 2006 05:14:32 -0000 1.72 *************** *** 81,85 **** // Create a new wxLuaState for the coroutine and set the wxLuaStateData // to the original wxLuaState's data ! wxLuaState wxlState(L1, WXLUASTATE_SETSTATE); delete wxlState.GetLuaStateRefData()->m_wxlStateData; wxlState.GetLuaStateRefData()->m_wxlStateData = wxlState_orig.GetLuaStateRefData()->m_wxlStateData; --- 81,85 ---- // Create a new wxLuaState for the coroutine and set the wxLuaStateData // to the original wxLuaState's data ! wxLuaState wxlState(L1, WXLUASTATE_COROUTINE); delete wxlState.GetLuaStateRefData()->m_wxlStateData; wxlState.GetLuaStateRefData()->m_wxlStateData = wxlState_orig.GetLuaStateRefData()->m_wxlStateData; *************** *** 853,856 **** --- 853,871 ---- return true; } + else if (type == WXLUASTATE_COROUTINE) + { + m_refData = new wxLuaStateRefData(); + M_WXLSTATEDATA->m_lua_State = L; + M_WXLSTATEDATA->m_lua_State_static = true; + wxLuaStateRefData::s_wxHashMapLuaStateRefData[L] = M_WXLSTATEDATA; + + // Stick us into the lua_State - push key, value + lua_pushstring( L, "__wxLuaStateRefData" ); + lua_pushlightuserdata( L, (void*)m_refData ); + // set the value + lua_settable( L, LUA_REGISTRYINDEX ); + + return true; + } m_refData = new wxLuaStateRefData(); Index: wxlbind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlbind.cpp,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** wxlbind.cpp 24 May 2006 04:50:02 -0000 1.35 --- wxlbind.cpp 6 Jun 2006 05:14:32 -0000 1.36 *************** *** 191,194 **** --- 191,196 ---- const char *cpIndex = lua_tostring(L, 2); + wxPrintf(wxT("wxLua_lua_setTableFunc '%s'\n"), lua2wx(cpIndex).c_str()); + if ((pClass != NULL) && lua_isuserdata(L, 1) && (lua_islightuserdata(L, 1) == 0) && |
From: John L. <jr...@us...> - 2006-06-06 05:14:39
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8826/wxLua/modules/wxlua/include Modified Files: wxlstate.h Log Message: add coroutine.wx.lua sample and fix coroutines after breaking it from require code Index: wxlstate.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/wxlstate.h,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** wxlstate.h 14 May 2006 07:48:09 -0000 1.47 --- wxlstate.h 6 Jun 2006 05:14:32 -0000 1.48 *************** *** 206,213 **** enum wxLuaState_Type { ! WXLUASTATE_ATTACH = 1, // Attach to a currently created lua_State ! // refing the existing wxLuaStateRefData ! WXLUASTATE_SETSTATE = 2 // Only set the lua_State and don't close it ! // when destroyed }; --- 206,215 ---- enum wxLuaState_Type { ! WXLUASTATE_ATTACH = 1, // Attach to a previously created wxLuaState's ! // lua_State refing the existing wxLuaStateRefData ! WXLUASTATE_SETSTATE = 2, // Set the lua_State, register the bindings, ! // and don't close it when destroyed ! WXLUASTATE_COROUTINE = 3 // This is a coroutine created state, just ! // track the state (internal use) }; |
From: John L. <jr...@us...> - 2006-06-06 05:14:38
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8826/wxLua/samples Modified Files: wxluasudoku.wx.lua Added Files: coroutine.wx.lua Log Message: add coroutine.wx.lua sample and fix coroutines after breaking it from require code Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** wxluasudoku.wx.lua 5 Jun 2006 05:14:24 -0000 1.54 --- wxluasudoku.wx.lua 6 Jun 2006 05:14:32 -0000 1.55 *************** *** 1328,1332 **** -- solution method iterating from low to high numbers and then from high to low. -- This should always find if there are at least two solutions. ! -- returns nil if no solution or [soln table, # guesses] for forward iteration function sudoku.IsUniquePuzzle(sudokuTable) --- 1328,1333 ---- -- solution method iterating from low to high numbers and then from high to low. -- This should always find if there are at least two solutions. ! -- returns nil if no solution or [s1, s2] if at least two solutions, else ! -- just the single unique solution function sudoku.IsUniquePuzzle(sudokuTable) *************** *** 1337,1343 **** if not s2 then return nil end ! if not sudoku.IsSamePuzzle(s1, s2) then return nil end ! return s1, g1 end --- 1338,1344 ---- if not s2 then return nil end ! if not sudoku.IsSamePuzzle(s1, s2) then return s1, s2 end ! return s1 end *************** *** 1711,1715 **** solution.<br> <br> ! If you want to start with a completely empty grid using <i>File->New</i>. If on the other hand, you want to start with a completely filled grid of random values, use <i>File->Generate</i> with the number of cell values --- 1712,1716 ---- solution.<br> <br> ! If you want to start with a completely empty grid use <i>File->New</i>. If on the other hand, you want to start with a completely filled grid of random values, use <i>File->Generate</i> with the number of cell values *************** *** 2171,2175 **** sudokuTables_pos = 0, -- Current position in the tables ! sudokuSolnTable = nil, -- solution to the current puzzle possNakedTable = nil, --- 2172,2177 ---- sudokuTables_pos = 0, -- Current position in the tables ! sudokuSolnTable = nil, -- solution to the current puzzle ! nonunique_init_puzzle = nil, -- nil for don't know, for true/false once checked possNakedTable = nil, *************** *** 3434,3438 **** function sudokuGUI.VerifyUniquePuzzle(sudokuTable) ! local ret = wx.wxOK local solve_progress = 0 --- 3436,3453 ---- function sudokuGUI.VerifyUniquePuzzle(sudokuTable) ! ! sudokuTable = sudoku.CalcInvalidCells(sudokuTable) ! local invalid_count = TableCount(sudokuTable.invalid) ! ! if invalid_count > 0 then ! local ret = wx.wxMessageBox( ! string.format("The initial values of the puzzle are invalid.\n".. ! "There are %d cells with duplicate values.\n".. ! "Please select Create and fix them before trying to solve.\n", invalid_count), ! "wxLuaSudoku - Invalid puzzle", ! wx.wxOK + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! return ! end local solve_progress = 0 *************** *** 3456,3459 **** --- 3471,3475 ---- end + local ret = wx.wxOK while ret == wx.wxOK do solve_progress = 0 *************** *** 3468,3483 **** wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! local s1, g = sudoku.IsUniquePuzzle(sudokuTable) progressDialog:Destroy() ! if s1 then return s1 elseif solve_ok == false then ! ret = wx.wxMessageBox("The puzzle was not fully verified. ".. "Press 'Ok' to restart checking or 'Cancel' to quit.", "wxLuaSudoku - Unfinished check", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, sudokuGUI.frame) ! else wx.wxMessageBox("The puzzle does not have a unique solution.\n".. "Use 'Create' to fix the problem, showing mistakes will be disabled.", --- 3484,3499 ---- wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! local s1, s2 = sudoku.IsUniquePuzzle(sudokuTable) progressDialog:Destroy() ! if s1 and (s2 == nil) then return s1 elseif solve_ok == false then ! ret = wx.wxMessageBox("The puzzle was not fully verified and therefore may not have a unique solution or a solution at all.\n".. "Press 'Ok' to restart checking or 'Cancel' to quit.", "wxLuaSudoku - Unfinished check", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, sudokuGUI.frame) ! elseif s1 and s2 then wx.wxMessageBox("The puzzle does not have a unique solution.\n".. "Use 'Create' to fix the problem, showing mistakes will be disabled.", *************** *** 3488,3491 **** --- 3504,3516 ---- sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) return nil + else + wx.wxMessageBox("The puzzle does not have a solution.\n".. + "Use 'Create' to fix the problem, showing mistakes will be disabled.", + "wxLuaSudoku - Unsolvable puzzle", + wx.wxOK + wx.wxICON_ERROR, + sudokuGUI.frame) + + sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) + return nil end end *************** *** 3497,3501 **** function sudokuGUI.SolveScanning() local s = TableCopy(sudokuGUI.GetCurrentTable()) ! local invalid = not TableIsEmpty(s.invalid) if invalid then --- 3522,3526 ---- function sudokuGUI.SolveScanning() local s = TableCopy(sudokuGUI.GetCurrentTable()) ! --[[ local invalid = not TableIsEmpty(s.invalid) if invalid then *************** *** 3529,3533 **** end end ! local s, count, changed_cells = sudoku.SolveScan(s) local changed_count = 0 --- 3554,3558 ---- end end ! ]] local s, count, changed_cells = sudoku.SolveScan(s) local changed_count = 0 *************** *** 3555,3559 **** s = TableCopy(sudokuGUI.GetCurrentTable()) end ! local invalid = not TableIsEmpty(s.invalid) if invalid then --- 3580,3584 ---- s = TableCopy(sudokuGUI.GetCurrentTable()) end ! --[[ local invalid = not TableIsEmpty(s.invalid) if invalid then *************** *** 3586,3590 **** end end ! local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Solving...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), --- 3611,3615 ---- end end ! ]] local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Solving...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), --- NEW FILE: coroutine.wx.lua --- -------------------------------------------------------------------------=--- -- Name: coroutine.wx.lua -- Purpose: Tests coroutines and wxIDLE_EVENTS -- Author: Leandro Motta Barros -- Created: 2006 -- Copyright: -- Licence: wxWidgets licence -------------------------------------------------------------------------=--- ------------------------------------------------------------------------------- -- ProgressWindow ------------------------------------------------------------------------------- ProgressWindow = { -- The 'wxDialog' being encapsulated by this class. dialog = nil, -- The label telling what's going on ("Processing thing 7/88...") label = nil, } -- The constructor. 'parent' is the parent window. 'workCoroutine' is the -- coroutine used to process whatever is desired. 'caption' is the caption to be -- used for this window. 'initialLabel' is the string that will be initially -- shown in the window. function ProgressWindow:new (parent, workCoroutine, caption, initialLabel) -- simple little sanity test to ensure that we can call binding functions local r = wx.wxRect(1,2,3,4) r:SetX(1) local o = { } setmetatable (o, self) self.__index = self -- Check parameters assert (type (workCoroutine) == "thread") assert (type (caption) == "string") assert (type (initialLabel) == "string") -- Create dialog o.dialog = wx.wxDialog(parent, wx.wxID_ANY, caption, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_DIALOG_STYLE) o.label = wx.wxTextCtrl (o.dialog, wx.wxID_ANY, intialLabel, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxTE_MULTILINE + wx.wxTE_READONLY) -- Handle idle events: run the coroutine's next "step" o.dialog:Connect (wx.wxEVT_IDLE, function (event) if coroutine.status (workCoroutine) ~= "dead" then local s, msg = coroutine.resume (workCoroutine) if not msg then o.dialog:Close() else o:setStatus (msg) end event:RequestMore() event:Skip() end end) -- Voilà return o end -- Sets the ProgressWindow's "status". For now, this means "change the text" -- being displayed in the window (usually something like "Doing this thing"). function ProgressWindow:setStatus (label) self.label:AppendText ("\n"..label) end ------------------------------------------------------------------------------- -- The main frame ------------------------------------------------------------------------------- local ID_THE_BUTTON = wx.wxID_HIGHEST + 100 frame = wx.wxFrame (wx.wxNull, wx.wxID_ANY, "wxLua Idle Events and Coroutines") -- ---------------------------------------------------------------------------- -- create a simple file menu local fileMenu = wx.wxMenu() fileMenu:Append(wx.wxID_EXIT, "E&xit", "Quit the program") -- create a simple help menu local helpMenu = wx.wxMenu() helpMenu:Append(wx.wxID_ABOUT, "&About", "About the wxLua Coroutine Sample") -- create a menu bar and append the file and help menus local menuBar = wx.wxMenuBar() menuBar:Append(fileMenu, "&File") menuBar:Append(helpMenu, "&Help") -- attach the menu bar into the frame frame:SetMenuBar(menuBar) -- connect the selection event of the exit menu item to an -- event handler that closes the window frame:Connect(wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) frame:Close(true) end ) -- connect the selection event of the about menu item frame:Connect(wx.wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) wx.wxMessageBox('This is the "About" dialog of the Coroutine wxLua sample.', "About wxLua", wx.wxOK + wx.wxICON_INFORMATION, frame) end ) -- ---------------------------------------------------------------------------- panel = wx.wxPanel(frame, wx.wxID_ANY) button = wx.wxButton (panel, ID_THE_BUTTON, "Perform some long operation") frame:Connect (ID_THE_BUTTON, wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) local function workFunc() for i = 1, 10 do coroutine.yield ("Performing step "..tostring(i).."/10") wx.wxSleep(1) end end local workCoroutine = coroutine.create (workFunc) local wndProgress = ProgressWindow:new (frame, workCoroutine, "Performing some long operation", "Performing step 1/many") wndProgress.dialog:ShowModal (true) wndProgress.dialog:Destroy() end) -- Show the main frame frame:Show (true) |
From: John L. <jr...@us...> - 2006-06-06 02:49:48
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv21763/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: lots of cleanup, faster and more complete initial puzzle soln, docs update Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** wxluasudoku.wx.lua 2 Jun 2006 04:41:08 -0000 1.53 --- wxluasudoku.wx.lua 5 Jun 2006 05:14:24 -0000 1.54 *************** *** 628,632 **** -- Remove a possible values from the row, col, block -- if exceptTable then don't remove it from exceptTable[cell#] = true ! function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable, break_empty) exceptTable = exceptTable or {} local cell --- 628,632 ---- -- Remove a possible values from the row, col, block -- if exceptTable then don't remove it from exceptTable[cell#] = true ! function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable, break_if_empty) exceptTable = exceptTable or {} [...2059 lines suppressed...] *************** *** 4781,4789 **** -- After being created - connect the size event to help MSW repaint the -- child windows ! sudokuGUI.frame:Connect(wx.wxEVT_SIZE, function (event) ! local width, height = sudokuGUI.frame:GetClientSize() ! --event:GetSize():GetWidth()/9, event:GetSize():GetHeight()/9 ! sudokuGUI.GetCellBestSize(width/9, height/9) sudokuGUI.Refresh() event:Skip(true) --- 4966,4973 ---- -- After being created - connect the size event to help MSW repaint the -- child windows ! sudokuGUI.cellWindows[1]:Connect(wx.wxEVT_SIZE, function (event) ! local width, height = sudokuGUI.cellWindows[1]:GetClientSize() ! sudokuGUI.GetCellBestSize(width, height) sudokuGUI.Refresh() event:Skip(true) |
From: Francesco M. <fr...@us...> - 2006-06-02 13:51:34
|
Update of /cvsroot/wxlua/website In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv24109 Modified Files: style.css Log Message: fixed header background colour for large screen resolutions Index: style.css =================================================================== RCS file: /cvsroot/wxlua/website/style.css,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** style.css 21 May 2006 13:20:22 -0000 1.16 --- style.css 2 Jun 2006 13:51:31 -0000 1.17 *************** *** 58,61 **** --- 58,62 ---- background-repeat: repeat-y; vertical-align: middle; + background-color: yellow; } |
From: John L. <jr...@us...> - 2006-06-02 04:41:11
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv8620/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: make generating unique solns faster, cleanup, docs Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** wxluasudoku.wx.lua 1 Jun 2006 22:50:54 -0000 1.52 --- wxluasudoku.wx.lua 2 Jun 2006 04:41:08 -0000 1.53 *************** *** 76,80 **** if not t then return atable end -- already gone end ! if (not only_if_empty) or ((type(t[args[#args]]) == "table") and (TableCount(t[args[#args]]) == 0)) then t[args[#args]] = nil end --- 76,80 ---- if not t then return atable end -- already gone end ! if (not only_if_empty) or ((type(t[args[#args]]) == "table") and TableIsEmpty(t[args[#args]])) then t[args[#args]] = nil [...1504 lines suppressed...] userPossMenu:Append( sudokuGUI.ID_USER_POSSIBLE_SETALL, "Set all...", "Set all pencil marks") ! userPossMenu:Append( sudokuGUI.ID_USER_POSSIBLE_INIT, "Calculate...", "Initialize pencil marks to calculated possible") possibleMenu:AppendMenu(ID_USER_POSSIBLE_MENU, "Pencil marks", userPossMenu, "Setup user possible values") *************** *** 4585,4588 **** --- 4662,4666 ---- local solveMenu = wx.wxMenu("", 0) solveMenu:Append(sudokuGUI.ID_VERIFY_PUZZLE, "Verify unique solution...", "Verify that the puzzle has only one solution") + solveMenu:AppendSeparator() local elimSolveMenu = wx.wxMenu("", 0) elimSolveMenu:AppendCheckItem(sudokuGUI.ID_ELIMINATE_NAKED, "Eliminate &naked groups", "Eliminate all naked groups from possible values") *************** *** 4639,4642 **** --- 4717,4721 ---- -- ------------------------------------------------------------------------ + -- Use single centralized menu/toolbar event handler sudokuGUI.frame:Connect(wx.wxID_ANY, wx.wxEVT_COMMAND_MENU_SELECTED, sudokuGUI.OnMenuEvent) |
From: John L. <jr...@us...> - 2006-06-01 22:51:00
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv9228/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: some cleanup Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** wxluasudoku.wx.lua 31 May 2006 21:26:32 -0000 1.51 --- wxluasudoku.wx.lua 1 Jun 2006 22:50:54 -0000 1.52 *************** *** 2961,2969 **** sudokuGUI.difficulty = keep ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true ! local msg_idx = 1 local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", --- 2961,2970 ---- sudokuGUI.difficulty = keep ! ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true ! local msg_idx = 1 local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", *************** *** 2976,2981 **** function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if solve_progress >= 10000 then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 2977,2981 ---- function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 2994,2997 **** --- 2994,3001 ---- -- have complete puzzle, now remove cells + local diff_count = 0 + local diff_i = 0 + local diff_cell = 0 + -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleDifficultyHook(count, i, cell) *************** *** 3010,3017 **** -- hook into brute force solver to update the generate puzzle progress dialog - solve_progress = 0 function sudoku.SolveBruteForceHook(guesses, cell) ! solve_progress = solve_progress + 1 ! if (solve_progress >= 10000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) --- 3014,3019 ---- -- hook into brute force solver to update the generate puzzle progress dialog function sudoku.SolveBruteForceHook(guesses, cell) ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) *************** *** 3021,3033 **** while ret == wx.wxOK do ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! solve_progress = 0 ! start_time = os.time() solve_completed = true progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", --- 3023,3035 ---- while ret == wx.wxOK do ! diff_count = 0 ! diff_i = 0 ! diff_cell = 0 ! solve_progress = 0 ! start_time = os.time() ! last_time = start_time solve_completed = true + msg_idx = 1 progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", *************** *** 3075,3079 **** local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press 'Ok' to correct them using 'Create' before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 3077,3082 ---- local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press 'Ok' to correct them using 'Create' before continuing ".. ! "otherwise 'Cancel' to ignore them.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 3112,3116 **** sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) else ! wx.wxMessageBox( "Unable to save file\n"..fileName, "wxLuaSudoku - Save file error", wx.wxOK + wx.wxICON_ERROR, --- 3115,3119 ---- sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) else ! wx.wxMessageBox( "Unable to save file\n'"..fileName.."'", "wxLuaSudoku - Save file error", wx.wxOK + wx.wxICON_ERROR, *************** *** 3195,3209 **** local ret = wx.wxOK ! local msg_idx = 1 ! local last_time = os.time() ! local solve_progress = 0 ! local start_time = os.time() local solve_completed = true -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 3198,3211 ---- local ret = wx.wxOK ! local solve_progress = 0 ! local start_time = os.time() ! local last_time = start_time local solve_completed = true + local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 3217,3229 **** while ret == wx.wxOK do ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! ! solve_progress = 0 ! start_time = os.time() solve_completed = true progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", --- 3219,3227 ---- while ret == wx.wxOK do ! solve_progress = 0 ! start_time = os.time() ! last_time = start_time solve_completed = true + msg_idx = 1 progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", *************** *** 3312,3316 **** -- Use the brute force method to solve it function sudokuGUI.SolveBruteForce(sudokuTable) - local solve_progress = 0 local s = TableCopy(sudokuTable or sudokuGUI.GetCurrentTable()) --- 3310,3313 ---- *************** *** 3352,3365 **** wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) local solve_completed = true ! local start_time = os.time() ! local last_time = start_time ! local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 3349,3362 ---- wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) + local solve_progress = 0 + local start_time = os.time() + local last_time = start_time local solve_completed = true ! local msg_idx = 1 -- define handler function here so it'll work w/o gui function sudoku.SolveBruteForceHook(guesses, cell) if solve_completed == false then return false end -- canceled ! solve_progress = iff(solve_progress+1 >= 10000, 0, solve_progress + 1) if (solve_progress-1)%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 3428,3436 **** local has_show_flag = false for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! local id = sudokuGUI.ID_ELIMINATE_NAKEDPAIRS + n - sudoku.ELIMINATE_FLAG_MIN sudokuTable.flags[n] = sudokuGUI.IsCheckedMenuItem(id) ! local show_id = sudokuGUI.ID_SHOW_NAKEDPAIRS + n - sudoku.ELIMINATE_FLAG_MIN ! if sudokuGUI.IsCheckedMenuItem(show_id) == true then has_show_flag = true end end --- 3425,3435 ---- local has_show_flag = false for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! local id = n + sudokuGUI.ID_ELIMINATE_NAKEDPAIRS - sudoku.ELIMINATE_FLAG_MIN sudokuTable.flags[n] = sudokuGUI.IsCheckedMenuItem(id) ! local show_id = n + sudokuGUI.ID_SHOW_NAKEDPAIRS - sudoku.ELIMINATE_FLAG_MIN ! if (not has_show_flag) and (sudokuGUI.IsCheckedMenuItem(show_id) == true) then ! has_show_flag = true ! end end *************** *** 3924,3928 **** local notebookPages = {} local page1 = sudokuGUI.PreferencesDialogPageUI.Create(notebook) ! notebook:AddPage(page1, "Fonts & Colors", true) notebookPages[1] = sudokuGUI.PreferencesDialogPageUI --- 3923,3927 ---- local notebookPages = {} local page1 = sudokuGUI.PreferencesDialogPageUI.Create(notebook) ! notebook:AddPage(page1, "Fonts and Colors", true) notebookPages[1] = sudokuGUI.PreferencesDialogPageUI *************** *** 4280,4287 **** function (event) -- need to solve it ourselves first ! if not sudokuGUI.sudokuSolnTable then ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) if not sudokuGUI.sudokuSolnTable then ! event:SetInt(0) -- uncheck sudokuGUI.frame:GetMenuBar():Check(sudokuGUI.ID_SHOW_MISTAKES, false) end --- 4279,4287 ---- function (event) -- need to solve it ourselves first ! if (event:IsChecked()) and (not sudokuGUI.sudokuSolnTable) then ! sudokuGUI.sudokuSolnTable = sudokuGUI.VerifyUniquePuzzle(sudokuGUI.GetInitTable()) ! if not sudokuGUI.sudokuSolnTable then ! event:SetInt(0) -- uncheck for MenuCheckUpdate function sudokuGUI.frame:GetMenuBar():Check(sudokuGUI.ID_SHOW_MISTAKES, false) end |
From: John L. <jr...@us...> - 2006-05-31 21:26:37
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv27525/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: more cleanup and added function to verify unique solution Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** wxluasudoku.wx.lua 31 May 2006 06:06:21 -0000 1.50 --- wxluasudoku.wx.lua 31 May 2006 21:26:32 -0000 1.51 *************** *** 21,24 **** --- 21,25 ---- -- ============================================================================ -- A simple function to implement "cond ? A : B", eg "result = iff(cond, A, B)" + -- note all terms must be able to be evaluated function iff(cond, A, B) if cond then return A else return B end end *************** *** 171,176 **** -- given the upper left cell of block you can iterate through the block using ! -- for n = 1, 9 do cell = block_cell + sudoku.LinearBlockCells[n] ... end ! sudoku.LinearBlockCells = { 0, 0, 0, 6, 6, 6, 12, 12, 12 } -- ============================================================================ --- 172,204 ---- -- given the upper left cell of block you can iterate through the block using ! -- for n = 1, 9 do cell = n + block_cell + sudoku.LinearBlockCellTable[n] ... end ! sudoku.LinearBlockCellTable = { -1, -1, -1, 5, 5, 5, 11, 11, 11 } ! ! sudoku.CellToRowTable = {} ! sudoku.CellToColTable = {} ! sudoku.BlockToRowTable = {} ! sudoku.BlockToColTable = {} ! sudoku.CellToBlockTable = {} ! sudoku.BlockToCellTable = {} ! ! for cell = 1, 81 do ! local row = math.floor(cell/9.1)+1 ! local col = cell-(row-1)*9 ! sudoku.CellToRowTable[cell] = row ! sudoku.CellToColTable[cell] = col ! ! local block_row = math.floor(row/3.5)+1 ! local block_col = math.floor(col/3.5)+1 ! sudoku.CellToBlockTable[cell] = (block_row-1)*3 + block_col ! end ! ! for block = 1, 9 do ! local row = math.floor(block/3.5)*3+1 ! local col = math.fmod(block-1,3)*3+1 ! sudoku.BlockToRowTable[block] = row ! sudoku.BlockToColTable[block] = col ! ! sudoku.BlockToCellTable[block] = (row-1)*9 + col ! end -- ============================================================================ *************** *** 179,189 **** local sudokuTable = { ! values = {}, -- array (1-81) of values[cell#] = value (0 means unset) row_values = {}, -- array (1-9) of values[row#][value] = { cell1, cell2... } col_values = {}, -- array (1-9) of values[col#][value] = { cell1, cell2... } block_values = {}, -- array (1-9) of values[block#][value] = { cell1, cell2... } ! possible = {}, -- possible values per cell, possible[cell# 1-81] = { val1, val2... } ! invalid = {}, -- array (1-81) of known invalid[cell#] = true/nil ! flags = {} -- extra flags for puzzle, eg. ELIMINATE_NAKED_PAIRS } --- 207,217 ---- local sudokuTable = { ! values = {}, -- array (1-81) of values[cell#] = value (0 means unset) row_values = {}, -- array (1-9) of values[row#][value] = { cell1, cell2... } col_values = {}, -- array (1-9) of values[col#][value] = { cell1, cell2... } block_values = {}, -- array (1-9) of values[block#][value] = { cell1, cell2... } ! possible = {}, -- possible values per cell, possible[cell# 1-81] = { val1, val2... } ! invalid = {}, -- array (1-81) of known invalid[cell#] = true/nil ! flags = {} -- extra flags for puzzle, eg. ELIMINATE_NAKED_PAIRS } *************** *** 346,358 **** -- Convert a linear cell index (1-81) into a row, col cell index (1-9) function sudoku.CellToRowCol(cell) ! local row = math.floor(cell/9.1)+1 ! local col = cell-(row-1)*9 ! return row, col end function sudoku.CellToRow(cell) ! return math.floor(cell/9.1)+1 end function sudoku.CellToCol(cell) ! return cell-math.floor(cell/9.1)*9 end --- 374,384 ---- -- Convert a linear cell index (1-81) into a row, col cell index (1-9) function sudoku.CellToRowCol(cell) ! return sudoku.CellToRowTable[cell], sudoku.CellToColTable[cell] end function sudoku.CellToRow(cell) ! return sudoku.CellToRowTable[cell] end function sudoku.CellToCol(cell) ! return sudoku.CellToColTable[cell] end *************** *** 378,411 **** -- Convert a row, col cell index (1-9) into the linear block number (1-9) function sudoku.RowColToBlock(row, col) ! local block_row = math.floor(row/3.5)+1 ! local block_col = math.floor(col/3.5)+1 ! return (block_row-1)*3 + block_col end -- Get the block (1-9) that this cell (1-81) is in function sudoku.CellToBlock(cell) ! local row, col = sudoku.CellToRowCol(cell) ! return sudoku.RowColToBlock(row, col) end -- Get the upper left cell of this block function sudoku.BlockToCell(block) ! return sudoku.RowColToCell(math.floor(block/3.5)*3+1, math.fmod(block-1,3)*3+1) end -- Convert a linear block index (1-9) into upper left row, col cell index (1-9) function sudoku.BlockToRowCol(block) ! local row = math.floor(block/3.5)*3+1 ! local col = math.fmod(block-1,3)*3+1 ! return row, col end function sudoku.BlockToRow(block) ! return math.floor(block/3.5)*3+1 end function sudoku.BlockToCol(block) ! return math.fmod(block-1,3)*3+1 end -- Get the upper left row, col cell of the block given by row, col function sudoku.RowColToBlockRowCol(row, col) ! local block_row = math.floor(row/3.5)*3+1 ! local block_col = math.floor(col/3.5)*3+1 ! return block_row, block_col end --- 404,431 ---- -- Convert a row, col cell index (1-9) into the linear block number (1-9) function sudoku.RowColToBlock(row, col) ! return sudoku.CellToBlockTable[sudoku.RowColToCell(row, col)] end -- Get the block (1-9) that this cell (1-81) is in function sudoku.CellToBlock(cell) ! return sudoku.CellToBlockTable[cell] end -- Get the upper left cell of this block function sudoku.BlockToCell(block) ! return sudoku.BlockToCellTable[block] end -- Convert a linear block index (1-9) into upper left row, col cell index (1-9) function sudoku.BlockToRowCol(block) ! return sudoku.BlockToRowTable[block], sudoku.BlockToColTable[block] end function sudoku.BlockToRow(block) ! return sudoku.BlockToRowTable[block] end function sudoku.BlockToCol(block) ! return sudoku.BlockToColTable[block] end -- Get the upper left row, col cell of the block given by row, col function sudoku.RowColToBlockRowCol(row, col) ! local block = sudoku.RowColToBlock(row, col) ! return sudoku.BlockToRowTable[block], sudoku.BlockToColTable[block] end *************** *** 417,422 **** -- Set the cell value at a specific row, col function sudoku.SetValue(row, col, value, sudokuTable) ! local cell = sudoku.RowColToCell(row, col) ! local block = sudoku.RowColToBlock(row, col) local old_value = sudokuTable.values[cell] --- 437,442 ---- -- Set the cell value at a specific row, col function sudoku.SetValue(row, col, value, sudokuTable) ! local cell = sudoku.RowColToCell(row, col) ! local block = sudoku.CellToBlock(cell) local old_value = sudokuTable.values[cell] *************** *** 513,519 **** -- Can this value be put into this cell given the other existing values? function sudoku.IsValidValue(row, col, value, sudokuTable) ! if sudoku.GetRowValues(row, sudokuTable)[value] or ! sudoku.GetColValues(col, sudokuTable)[value] or ! sudoku.GetBlockValues(sudoku.RowColToBlock(row, col), sudokuTable)[value] then return false end --- 533,539 ---- -- Can this value be put into this cell given the other existing values? function sudoku.IsValidValue(row, col, value, sudokuTable) ! if sudokuTable.row_values[row][value] or ! sudokuTable.col_values[col][value] or ! sudokuTable.block_values[sudoku.RowColToBlock(row, col)][value] then return false end *************** *** 528,532 **** for n = 1, 9 do ! for i, cell_table in pairs(sudoku.GetRowValues(n, sudokuTable)) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do --- 548,552 ---- for n = 1, 9 do ! for i, cell_table in pairs(sudokuTable.row_values[n]) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do *************** *** 535,539 **** end end ! for i, cell_table in pairs(sudoku.GetColValues(n, sudokuTable)) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do --- 555,559 ---- end end ! for i, cell_table in pairs(sudokuTable.col_values[n]) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do *************** *** 542,546 **** end end ! for i, cell_table in pairs(sudoku.GetBlockValues(n, sudokuTable)) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do --- 562,566 ---- end end ! for i, cell_table in pairs(sudokuTable.block_values[n]) do if TableCount(cell_table) > 1 then for j, cell in pairs(cell_table) do *************** *** 587,609 **** -- Remove a possible values from the row, col, block -- if exceptTable then don't remove it from exceptTable[cell#] = true ! function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable) exceptTable = exceptTable or {} local cell local block_cell = sudoku.BlockToCell(sudoku.RowColToBlock(row, col)) for rcb = 1, 9 do cell = sudoku.RowColToCell(rcb, col) ! if not exceptTable[cell] then ! sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) end cell = sudoku.RowColToCell(row, rcb) ! if not exceptTable[cell] then ! sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) end ! cell = rcb - 1 + block_cell + sudoku.LinearBlockCells[rcb] ! if not exceptTable[cell] then ! sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) end end --- 607,633 ---- -- Remove a possible values from the row, col, block -- if exceptTable then don't remove it from exceptTable[cell#] = true ! function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable, break_empty) exceptTable = exceptTable or {} local cell local block_cell = sudoku.BlockToCell(sudoku.RowColToBlock(row, col)) + break_empty = break_empty or false for rcb = 1, 9 do cell = sudoku.RowColToCell(rcb, col) ! if (not exceptTable[cell]) and sudokuTable.possible[cell][value] then ! sudokuTable.possible[cell][value] = nil ! if break_empty and (not sudoku.HasCellValue(cell, sudokuTable)) and TableIsEmpty(sudokuTable.possible[cell]) then return nil end end cell = sudoku.RowColToCell(row, rcb) ! if (not exceptTable[cell]) and sudokuTable.possible[cell][value] then ! sudokuTable.possible[cell][value] = nil ! if break_empty and (not sudoku.HasCellValue(cell, sudokuTable)) and TableIsEmpty(sudokuTable.possible[cell]) then return nil end end ! cell = rcb + block_cell + sudoku.LinearBlockCellTable[rcb] ! if (not exceptTable[cell]) and sudokuTable.possible[cell][value] then ! sudokuTable.possible[cell][value] = nil ! if break_empty and (not sudoku.HasCellValue(cell, sudokuTable)) and TableIsEmpty(sudokuTable.possible[cell]) then return nil end end end *************** *** 655,681 **** end - -- For row, col, block check to see that there is at least one possible value - -- for any empty cells, returns true/false - function sudoku.HasPossibleForEmptyCellsAll(row, col, sudokuTable) - local cell - local block_cell = sudoku.BlockToCell(sudoku.RowColToBlock(row, col)) - - for rcb = 1, 9 do - cell = sudoku.RowColToCell(rcb, col) - if (not sudoku.HasCellValue(cell, sudokuTable)) and - TableIsEmpty(sudokuTable.possible[cell]) then return false end - - cell = sudoku.RowColToCell(row, rcb) - if (not sudoku.HasCellValue(cell, sudokuTable)) and - TableIsEmpty(sudokuTable.possible[cell]) then return false end - - cell = rcb - 1 + block_cell + sudoku.LinearBlockCells[rcb] - if (not sudoku.HasCellValue(cell, sudokuTable)) and - TableIsEmpty(sudokuTable.possible[cell]) then return false end - end - - return true - end - -- Get the count of all possible values for rows, cols, and blocks -- returns 3 tables row_possible[row#][value] = #times possible value occurs in row --- 679,682 ---- *************** *** 1248,1251 **** --- 1249,1253 ---- function sudoku.DoSolveBruteForce(sudokuTable, backwards, simpleTable, guesses, cell) local s = simpleTable + local g, empty_possible if sudoku.SolveBruteForceHook then *************** *** 1268,1289 **** s = sudoku.RemoveCellPossible(cell, k, s) ! -- start a new table and test out this guess w/ new table ! local s1 = sudoku.RemovePossibleAll(row, col, k, TableCopy(s)) ! local g ! -- don't use SetValue since we only care about possible s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) guesses[cell] = guesses[cell] + 1 guesses.current = guesses.current + 1 - if sudoku.HasPossibleForEmptyCellsAll(row, col, s1) then - - s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) - -- if s1 then success! we're all done if s1 then ! local s2 = TableCopy(sudokuTable) ! s2 = sudoku.SetValues(s1.values, s2) ! return s2, g ! end end end --- 1270,1292 ---- s = sudoku.RemoveCellPossible(cell, k, s) ! local s1 = TableCopy(s) -- don't use SetValue since we only care about possible s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) + + -- start a new table and test out this guess w/ new table + s1 = sudoku.RemovePossibleAll(row, col, k, s1, nil, true) + guesses[cell] = guesses[cell] + 1 guesses.current = guesses.current + 1 if s1 then ! s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) ! -- if s1 then success! we're all done ! if s1 then ! -- copy all original data back and just set the values ! local s2 = TableCopy(sudokuTable) ! s2 = sudoku.SetValues(s1.values, s2) ! return s2, g ! end end end *************** *** 1941,1944 **** --- 1944,1948 ---- ID_SHOW_HIDDENQUADS = NewID(), -- mark hidden quads + ID_VERIFY_PUZZLE = NewID(), ID_ELIMINATE_MENU = NewID(), ID_ELIMINATE_NAKED = NewID(), -- eliminate naked groups *************** *** 2170,2174 **** brush:Delete() ! local sudokuTable = sudokuGUI.GetCurrentGrid() local value_str, is_init = sudokuGUI.GetCellValueString(cell) --- 2174,2178 ---- brush:Delete() ! local sudokuTable = sudokuGUI.GetCurrentTable() local value_str, is_init = sudokuGUI.GetCellValueString(cell) *************** *** 2273,2277 **** local show_errors = sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_ERRORS) if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_CREATE) then show_errors = true end ! if show_errors then show_errors = sudokuGUI.GetCurrentGrid().invalid[cell] end local show_mistakes = sudokuGUI.sudokuSolnTable and sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) --- 2277,2281 ---- local show_errors = sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_ERRORS) if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_CREATE) then show_errors = true end ! if show_errors then show_errors = sudokuGUI.GetCurrentTable().invalid[cell] end local show_mistakes = sudokuGUI.sudokuSolnTable and sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) *************** *** 2465,2469 **** if printer:Print(sudokuGUI.frame, luaPrintout, true) == false then if printer:GetLastError() == wx.wxPRINTER_ERROR then ! wx.wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "wxLuaSudoku Printout", wx.wxOK, sudokuGUI.frame) --- 2469,2474 ---- if printer:Print(sudokuGUI.frame, luaPrintout, true) == false then if printer:GetLastError() == wx.wxPRINTER_ERROR then ! wx.wxMessageBox("There was a problem printing.\n".. ! "Perhaps your current printer is not setup correctly?", "wxLuaSudoku Printout", wx.wxOK, sudokuGUI.frame) *************** *** 2485,2489 **** local result = preview:Ok() if result == false then ! wx.wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "wxLuaSudoku print preview error", wx.wxOK, sudokuGUI.frame) --- 2490,2495 ---- local result = preview:Ok() if result == false then ! wx.wxMessageBox("There was a problem previewing.\n".. ! "Perhaps your current printer is not setup correctly?", "wxLuaSudoku print preview error", wx.wxOK, sudokuGUI.frame) *************** *** 2791,2799 **** sudokuGUI.sudokuSolnTable = nil -- don't know anymore else ! local s = sudokuGUI.GetCurrentGrid() if (not is_init) and (sudoku.GetCellValue(cell, s) ~= value) then local s = TableCopy(s) s = sudoku.SetValue(row, col, value, s) ! sudokuGUI.AddGrid(s) end end --- 2797,2805 ---- sudokuGUI.sudokuSolnTable = nil -- don't know anymore else ! local s = sudokuGUI.GetCurrentTable() if (not is_init) and (sudoku.GetCellValue(cell, s) ~= value) then local s = TableCopy(s) s = sudoku.SetValue(row, col, value, s) ! sudokuGUI.AddTable(s) end end *************** *** 2802,2816 **** end ! -- Get the current grid to use ! function sudokuGUI.GetCurrentGrid() return sudokuGUI.sudokuTables[sudokuGUI.sudokuTables_pos] end ! -- Set the current grid to this grid ! function sudokuGUI.SetCurrentGrid(sudokuTable) sudokuGUI.sudokuTables[sudokuGUI.sudokuTables_pos] = sudokuTable end ! -- Add a grid to the list of grids, removing any past the current position, -- find possible, and refresh ! function sudokuGUI.AddGrid(sudokuTable) while TableCount(sudokuGUI.sudokuTables) > sudokuGUI.sudokuTables_pos do table.remove(sudokuGUI.sudokuTables) --- 2808,2835 ---- end ! -- Get the initial sudoku table ! function sudokuGUI.GetInitTable() ! return sudokuGUI.sudokuTables[1] ! end ! -- Set the initial sudoku table, clearing all others ! function sudokuGUI.SetInitTable(sudokuTable, solnTable) ! sudokuGUI.sudokuSolnTable = solnTable ! sudokuGUI.sudokuTables_pos = 1 ! sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, sudokuTable) ! sudokuGUI.UpdateTable() -- resets possible and refreshes too ! end ! ! -- Get the current sudoku table to use ! function sudokuGUI.GetCurrentTable() return sudokuGUI.sudokuTables[sudokuGUI.sudokuTables_pos] end ! -- Set the current sudoku table to this table ! function sudokuGUI.SetCurrentTable(sudokuTable) sudokuGUI.sudokuTables[sudokuGUI.sudokuTables_pos] = sudokuTable end ! -- Add a sudoku table to the list of tables, removing any past the current position, -- find possible, and refresh ! function sudokuGUI.AddTable(sudokuTable) while TableCount(sudokuGUI.sudokuTables) > sudokuGUI.sudokuTables_pos do table.remove(sudokuGUI.sudokuTables) *************** *** 2838,2843 **** if sudoku.HasCellValue(cell, sudokuGUI.sudokuTables[1]) then return tostring(sudoku.GetCellValue(cell, sudokuGUI.sudokuTables[1])), true ! elseif sudoku.HasCellValue(cell, sudokuGUI.GetCurrentGrid()) then ! value = tostring(sudoku.GetCellValue(cell, sudokuGUI.GetCurrentGrid())) end --- 2857,2862 ---- if sudoku.HasCellValue(cell, sudokuGUI.sudokuTables[1]) then return tostring(sudoku.GetCellValue(cell, sudokuGUI.sudokuTables[1])), true ! elseif sudoku.HasCellValue(cell, sudokuGUI.GetCurrentTable()) then ! value = tostring(sudoku.GetCellValue(cell, sudokuGUI.GetCurrentTable())) end *************** *** 2857,2861 **** -- Create a new empty puzzle function sudokuGUI.NewPuzzle() ! local ret = wx.wxMessageBox("Clear the current puzzle and start anew?\n".. "Use 'Create' to enter the initial values.", "wxLuaSudoku - New puzzle?", --- 2876,2880 ---- -- Create a new empty puzzle function sudokuGUI.NewPuzzle() ! local ret = wx.wxMessageBox("Clear all the values in the current puzzle and start anew?\n".. "Use 'Create' to enter the initial values.", "wxLuaSudoku - New puzzle?", *************** *** 2864,2873 **** if ret == wx.wxOK then ! sudokuGUI.sudokuSolnTable = nil -- don't know anymore ! local s = sudoku.CreateTable() ! sudokuGUI.sudokuTables_pos = 1 ! sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s) ! sudokuGUI.UpdateTable() -- resets possible and refreshes too end end --- 2883,2887 ---- if ret == wx.wxOK then ! sudokuGUI.SetInitTable(sudoku.CreateTable(), nil) end end *************** *** 2914,2919 **** local ret = wx.wxMessageBox( "The initial puzzle you've created has invalid values.\n".. ! "Press Ok to correct them before continuing.\n".. ! "If you press cancel then don't blame me if things don't work out for you.", "wxLuaSudoku - Invalid initial puzzle!", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 2928,2933 ---- local ret = wx.wxMessageBox( "The initial puzzle you've created has invalid values.\n".. ! "Press 'Ok' to correct them before continuing.\n".. ! "If you press 'Cancel' don't blame me if things don't work out for you.", "wxLuaSudoku - Invalid initial puzzle!", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 2925,2949 **** end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) ! ! if not sudokuGUI.sudokuSolnTable then ! -- try to make them correct the puzzle ! local ret = wx.wxMessageBox( ! "The initial puzzle you've created cannot be or was not solved ".. ! "and therefore mistakes cannot be marked.\n".. ! "Press Ok to continue 'Creating'.\n".. ! "If you press cancel then showing mistakes will be disabled.", ! "wxLuaSudoku - Invalid initial puzzle", ! wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! ! if ret == wx.wxOK then ! sudokuGUI.CheckMenuItem(sudokuGUI.ID_CREATE, true) ! init = true ! else ! sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) ! end ! end end end --- 2939,2943 ---- end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! sudokuGUI.sudokuSolnTable = sudokuGUI.VerifyUniquePuzzle(sudokuGUI.GetInitTable()) end end *************** *** 3047,3061 **** if s1 then ! sudokuGUI.sudokuSolnTable = TableCopy(s) ! ! sudokuGUI.sudokuTables_pos = 1 ! sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s1) ! sudokuGUI.UpdateTable() -- resets possible and refreshes too break else ret = wx.wxMessageBox( ! "The puzzle was not fully generated.".. ! "Press Ok to continue generating or Cancel to quit.", "wxLuaSudoku - Unfinished generation", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 3041,3050 ---- if s1 then ! sudokuGUI.SetInitTable(s1, TableCopy(s)) break else ret = wx.wxMessageBox( ! "The puzzle was not fully generated. ".. ! "Press 'Ok' to continue generating or 'Cancel' to quit.", "wxLuaSudoku - Unfinished generation", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 3079,3088 **** if s then sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) - sudokuGUI.sudokuTables_pos = 1 - sudokuGUI.sudokuTables = {} - table.insert(sudokuGUI.sudokuTables, s) - sudokuGUI.UpdateTable() -- resets possible and refreshes too ! sudokuGUI.sudokuSolnTable = nil -- reset if not TableIsEmpty(sudokuGUI.sudokuTables[1].invalid) then --- 3068,3073 ---- if s then sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) ! sudokuGUI.SetInitTable(s, nil) if not TableIsEmpty(sudokuGUI.sudokuTables[1].invalid) then *************** *** 3090,3094 **** local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press Ok to correct them using 'Create' before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 3075,3079 ---- local ret = wx.wxMessageBox( "The puzzle you've opened has invalid values.\n".. ! "Press 'Ok' to correct them using 'Create' before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 3099,3124 **** end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! local ret = wx.wxOK ! while ret == wx.wxOK do ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) ! ! if not sudokuGUI.sudokuSolnTable then ! -- try to make them correct the puzzle ! local ret = wx.wxMessageBox( ! "The initial puzzle you've opened cannot be or was not solved \n".. ! "and therefore mistakes cannot be marked.\n".. ! "If you press cancel then showing mistakes will be disabled.", ! "wxLuaSudoku - Invalid puzzle", ! wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! ! if ret == wx.wxCANCEL then ! sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) ! break ! end ! else ! break ! end ! end end else --- 3084,3088 ---- end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! sudokuGUI.sudokuSolnTable = sudokuGUI.VerifyUniquePuzzle(sudokuGUI.GetInitTable()) end else *************** *** 3144,3148 **** sudokuGUI.fileName = fn:GetFullName() ! result = sudoku.Save(fileName, sudokuGUI.GetCurrentGrid()) if result then sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) --- 3108,3112 ---- sudokuGUI.fileName = fn:GetFullName() ! result = sudoku.Save(fileName, sudokuGUI.GetCurrentTable()) if result then sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) *************** *** 3228,3234 **** end -- Use the scanning method to solve it function sudokuGUI.SolveScanning() ! local s = TableCopy(sudokuGUI.GetCurrentGrid()) local invalid = not TableIsEmpty(s.invalid) --- 3192,3267 ---- end + function sudokuGUI.VerifyUniquePuzzle(sudokuTable) + local ret = wx.wxOK + + local msg_idx = 1 + local last_time = os.time() + local solve_progress = 0 + local start_time = os.time() + local solve_completed = true + + -- define handler function here so it'll work w/o gui + function sudoku.SolveBruteForceHook(guesses, cell) + if solve_completed == false then return false end -- canceled + solve_progress = solve_progress + 1 + if (solve_progress >= 1000) then solve_progress = 0 end + if (solve_progress-1)%10 ~= 0 then return true end + if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then + msg_idx = msg_idx + 1 + last_time = os.time() + end + local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[msg_idx], guesses.current, cell) + solve_completed = progressDialog:Update(solve_progress/10, msg) + return solve_completed + end + + while ret == wx.wxOK do + msg_idx = 1 + last_time = os.time() + local diff_count = 0 + local diff_i = 0 + local diff_cell = 0 + + solve_progress = 0 + start_time = os.time() + solve_completed = true + + progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", + string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), + 10000, + sudokuGUI.frame, + wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) + + local s1, g = sudoku.IsUniquePuzzle(sudokuTable) + progressDialog:Destroy() + + if s1 then + return s1 + elseif solve_completed == false then + ret = wx.wxMessageBox( + "The puzzle was not fully verified. ".. + "Press 'Ok' to continue checking or 'Cancel' to quit.", + "wxLuaSudoku - Unfinished check", + wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, + sudokuGUI.frame ) + else + wx.wxMessageBox( + "The puzzle does not have a unique solution.\n".. + "Use 'Create' to fix the problem, showing mistakes will be disabled.", + "wxLuaSudoku - Nonunique puzzle", + wx.wxOK + wx.wxICON_ERROR, + sudokuGUI.frame ) + + sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) + return nil + end + end + + return nil + end + -- Use the scanning method to solve it function sudokuGUI.SolveScanning() ! local s = TableCopy(sudokuGUI.GetCurrentTable()) local invalid = not TableIsEmpty(s.invalid) *************** *** 3255,3260 **** local fixedS = sudokuGUI.FixInvalid(s, true) if fixedS then ! sudokuGUI.AddGrid(fixedS) ! s = TableCopy(sudokuGUI.GetCurrentGrid()) else return --- 3288,3293 ---- local fixedS = sudokuGUI.FixInvalid(s, true) if fixedS then ! sudokuGUI.AddTable(fixedS) ! s = TableCopy(sudokuGUI.GetCurrentTable()) else return *************** *** 3266,3270 **** local changed_count = 0 if changed_cells then ! sudokuGUI.AddGrid(s) changed_count = TableCount(changed_cells) end --- 3299,3303 ---- local changed_count = 0 if changed_cells then ! sudokuGUI.AddTable(s) changed_count = TableCount(changed_cells) end *************** *** 3281,3285 **** local solve_progress = 0 ! local s = TableCopy(sudokuTable or sudokuGUI.GetCurrentGrid()) local invalid = not TableIsEmpty(s.invalid) if invalid then --- 3314,3318 ---- local solve_progress = 0 ! local s = TableCopy(sudokuTable or sudokuGUI.GetCurrentTable()) local invalid = not TableIsEmpty(s.invalid) if invalid then *************** *** 3305,3310 **** local fixedS = sudokuGUI.FixInvalid(s, true) if fixedS then ! sudokuGUI.AddGrid(fixedS) ! s = TableCopy(sudokuGUI.GetCurrentGrid()) else return --- 3338,3343 ---- local fixedS = sudokuGUI.FixInvalid(s, true) if fixedS then ! sudokuGUI.AddTable(fixedS) ! s = TableCopy(sudokuGUI.GetCurrentTable()) else return *************** *** 3359,3363 **** elseif not sudokuTable then s.flags = flags -- restore flags ! sudokuGUI.AddGrid(s) -- we solved the current grid else s.flags = flags -- restore flags --- 3392,3396 ---- elseif not sudokuTable then s.flags = flags -- restore flags ! sudokuGUI.AddTable(s) -- we solved the current grid else s.flags = flags -- restore flags *************** *** 3389,3393 **** function sudokuGUI.UpdateTable(refresh) ! local sudokuTable = sudokuGUI.GetCurrentGrid() sudokuGUI.block_refresh = true --- 3422,3426 ---- function sudokuGUI.UpdateTable(refresh) ! local sudokuTable = sudokuGUI.GetCurrentTable() sudokuGUI.block_refresh = true *************** *** 3414,3418 **** end end ! sudokuGUI.SetCurrentGrid(sudokuTable) sudokuGUI.block_refresh = false --- 3447,3451 ---- end end ! sudokuGUI.SetCurrentTable(sudokuTable) sudokuGUI.block_refresh = false *************** *** 4226,4230 **** sudokuGUI.MenuId[sudokuGUI.ID_COPY_PUZZLE] = function (event) ! local str = sudoku.ToString(sudokuGUI.GetCurrentGrid()) if wx.wxClipboard_Get():Open() then wx.wxClipboard_Get():SetData(wx.wxTextDataObject(str)) --- 4259,4263 ---- sudokuGUI.MenuId[sudokuGUI.ID_COPY_PUZZLE] = function (event) ! local str = sudoku.ToString(sudokuGUI.GetCurrentTable()) if wx.wxClipboard_Get():Open() then wx.wxClipboard_Get():SetData(wx.wxTextDataObject(str)) *************** *** 4327,4331 **** sudokuGUI.frame ) if ret == wx.wxOK then ! local s = sudokuGUI.GetCurrentGrid() for cell = 1, 81 do sudokuGUI.pencilMarks[cell] = {} --- 4360,4364 ---- sudokuGUI.frame ) if ret == wx.wxOK then ! local s = sudokuGUI.GetCurrentTable() for cell = 1, 81 do sudokuGUI.pencilMarks[cell] = {} *************** *** 4360,4363 **** --- 4393,4404 ---- sudokuGUI.MenuId[sudokuGUI.ID_SHOW_HIDDENQUADS] = function(event) sudokuGUI.MenuCheckUpdate(event) end -- ---------------------------------------------------------------------------- + sudokuGUI.MenuId[sudokuGUI.ID_VERIFY_PUZZLE] = + function (event) + local s = sudokuGUI.VerifyUniquePuzzle(sudokuGUI.GetInitTable()) + if s then + sudokuGUI.sudokuSolnTable = s + end + end + sudokuGUI.MenuId[sudokuGUI.ID_ELIMINATE_NAKED] = function (event) *************** *** 4385,4405 **** sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANSINGLES] = function (event) ! local s, changed_cells = sudoku.SolveScanSingles(TableCopy(sudokuGUI.GetCurrentGrid())) ! if changed_cells then sudokuGUI.AddGrid(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANROWS] = function (event) ! local s, changed_cells = sudoku.SolveScanRows(TableCopy(sudokuGUI.GetCurrentGrid())) ! if changed_cells then sudokuGUI.AddGrid(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANCOLS] = function (event) ! local s, changed_cells = sudoku.SolveScanCols(TableCopy(sudokuGUI.GetCurrentGrid())) ! if changed_cells then sudokuGUI.AddGrid(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANBLOCKS] = function (event) ! local s, changed_cells = sudoku.SolveScanBlocks(TableCopy(sudokuGUI.GetCurrentGrid())) ! if changed_cells then sudokuGUI.AddGrid(s) end end --- 4426,4446 ---- sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANSINGLES] = function (event) ! local s, changed_cells = sudoku.SolveScanSingles(TableCopy(sudokuGUI.GetCurrentTable())) ! if changed_cells then sudokuGUI.AddTable(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANROWS] = function (event) ! local s, changed_cells = sudoku.SolveScanRows(TableCopy(sudokuGUI.GetCurrentTable())) ! if changed_cells then sudokuGUI.AddTable(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANCOLS] = function (event) ! local s, changed_cells = sudoku.SolveScanCols(TableCopy(sudokuGUI.GetCurrentTable())) ! if changed_cells then sudokuGUI.AddTable(s) end end sudokuGUI.MenuId[sudokuGUI.ID_SOLVE_SCANBLOCKS] = function (event) ! local s, changed_cells = sudoku.SolveScanBlocks(TableCopy(sudokuGUI.GetCurrentTable())) ! if changed_cells then sudokuGUI.AddTable(s) end end *************** *** 4543,4546 **** --- 4584,4588 ---- local solveMenu = wx.wxMenu("", 0) + solveMenu:Append(sudokuGUI.ID_VERIFY_PUZZLE, "Verify unique solution...", "Verify that the puzzle has only one solution") local elimSolveMenu = wx.wxMenu("", 0) elimSolveMenu:AppendCheckItem(sudokuGUI.ID_ELIMINATE_NAKED, "Eliminate &naked groups", "Eliminate all naked groups from possible values") |
From: John L. <jr...@us...> - 2006-05-31 06:06:31
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv18622/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: check to see if soln is possible and cleanup Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** wxluasudoku.wx.lua 30 May 2006 22:56:29 -0000 1.49 --- wxluasudoku.wx.lua 31 May 2006 06:06:21 -0000 1.50 *************** *** 655,658 **** --- 655,681 ---- end + -- For row, col, block check to see that there is at least one possible value + -- for any empty cells, returns true/false + function sudoku.HasPossibleForEmptyCellsAll(row, col, sudokuTable) + local cell + local block_cell = sudoku.BlockToCell(sudoku.RowColToBlock(row, col)) + + for rcb = 1, 9 do + cell = sudoku.RowColToCell(rcb, col) + if (not sudoku.HasCellValue(cell, sudokuTable)) and + TableIsEmpty(sudokuTable.possible[cell]) then return false end + + cell = sudoku.RowColToCell(row, rcb) + if (not sudoku.HasCellValue(cell, sudokuTable)) and + TableIsEmpty(sudokuTable.possible[cell]) then return false end + + cell = rcb - 1 + block_cell + sudoku.LinearBlockCells[rcb] + if (not sudoku.HasCellValue(cell, sudokuTable)) and + TableIsEmpty(sudokuTable.possible[cell]) then return false end + end + + return true + end + -- Get the count of all possible values for rows, cols, and blocks -- returns 3 tables row_possible[row#][value] = #times possible value occurs in row *************** *** 1253,1256 **** --- 1276,1282 ---- guesses[cell] = guesses[cell] + 1 guesses.current = guesses.current + 1 + + if sudoku.HasPossibleForEmptyCellsAll(row, col, s1) then + s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) -- if s1 then success! we're all done *************** *** 1260,1263 **** --- 1286,1290 ---- return s2, g end + end end end *************** *** 2898,2901 **** --- 2925,2929 ---- end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then + sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) *************** *** 2926,2930 **** end ! sudokuGUI.UpdateGUI() end --- 2954,2958 ---- end ! sudokuGUI.UpdateTable() end *************** *** 2945,2961 **** local msg_idx = 1 - local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 100, sudokuGUI.frame, wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) - -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then --- 2973,2987 ---- local msg_idx = 1 local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 10000, sudokuGUI.frame, wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleHook(count, cell) if solve_completed == false then return false end -- canceled solve_progress = solve_progress + 1 ! if solve_progress >= 10000 then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then *************** *** 2964,2993 **** end local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[msg_idx], count, cell) ! solve_completed = progressDialog:Update(solve_progress/10, msg) return solve_completed end local s, count = sudoku.GeneratePuzzle() - progressDialog:Destroy() - if not s then return end ! local solve_progress = 0 ! local start_time = os.time() ! local solve_completed = true ! ! local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", ! string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 81 - sudokuGUI.difficulty, ! sudokuGUI.frame, ! wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! -- define handler function here so it'll work w/o gui --- 2990,3002 ---- end local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[msg_idx], count, cell) ! solve_completed = progressDialog:Update(solve_progress, msg) return solve_completed end local s, count = sudoku.GeneratePuzzle() progressDialog:Destroy() if not s then return end ! -- have complete puzzle, now remove cells -- define handler function here so it'll work w/o gui *************** *** 3010,3028 **** function sudoku.SolveBruteForceHook(guesses, cell) solve_progress = solve_progress + 1 ! if (solve_progress >= 1000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) end ! sudokuGUI.sudokuSolnTable = TableCopy(s) ! local s1 = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, TableCopy(s)) ! progressDialog:Destroy() ! if s1 then ! sudokuGUI.sudokuTables_pos = 1 ! sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s1) ! sudokuGUI.UpdateTable() -- resets possible and refreshes too end end --- 3019,3065 ---- function sudoku.SolveBruteForceHook(guesses, cell) solve_progress = solve_progress + 1 ! if (solve_progress >= 10000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) end + local ret = wx.wxOK ! while ret == wx.wxOK do ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! solve_progress = 0 ! start_time = os.time() ! solve_completed = true ! ! progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", ! string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 81 - sudokuGUI.difficulty + 1, ! sudokuGUI.frame, ! wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! ! local s1 = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, TableCopy(s)) ! progressDialog:Destroy() ! ! if s1 then ! sudokuGUI.sudokuSolnTable = TableCopy(s) ! ! sudokuGUI.sudokuTables_pos = 1 ! sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s1) ! sudokuGUI.UpdateTable() -- resets possible and refreshes too ! break ! else ! ret = wx.wxMessageBox( ! "The puzzle was not fully generated.".. ! "Press Ok to continue generating or Cancel to quit.", ! "wxLuaSudoku - Unfinished generation", ! wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! end end end *************** *** 3052,3057 **** -- make them correct the puzzle local ret = wx.wxMessageBox( ! "The puzzle you've opened has invalid values or cannot be solved.\n".. ! "Press Ok to correct them using Create before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, --- 3089,3094 ---- -- make them correct the puzzle local ret = wx.wxMessageBox( ! "The puzzle you've opened has invalid values.\n".. ! "Press Ok to correct them using 'Create' before continuing.", "wxLuaSudoku - Invalid puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, *************** *** 3062,3079 **** end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) ! if not sudokuGUI.sudokuSolnTable then ! -- try to make them correct the puzzle ! local ret = wx.wxMessageBox( ! "The initial puzzle you've opened cannot be or was not solved \n".. ! "and therefore mistakes cannot be marked.\n".. ! "If you press cancel then showing mistakes will be disabled.", ! "wxLuaSudoku - Invalid puzzle", ! wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! if ret == wx.wxCANCEL then ! sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) end end --- 3099,3122 ---- end elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then ! local ret = wx.wxOK ! while ret == wx.wxOK do ! sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) ! if not sudokuGUI.sudokuSolnTable then ! -- try to make them correct the puzzle ! local ret = wx.wxMessageBox( ! "The initial puzzle you've opened cannot be or was not solved \n".. ! "and therefore mistakes cannot be marked.\n".. ! "If you press cancel then showing mistakes will be disabled.", ! "wxLuaSudoku - Invalid puzzle", ! wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, ! sudokuGUI.frame ) ! if ret == wx.wxCANCEL then ! sudokuGUI.CheckMenuItem(sudokuGUI.ID_SHOW_MISTAKES, false) ! break ! end ! else ! break end end *************** *** 3090,3094 **** function sudokuGUI.SaveAsPuzzle() ! local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Save file", sudokuGUI.filePath, sudokuGUI.fileName, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", --- 3133,3137 ---- function sudokuGUI.SaveAsPuzzle() ! local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Save puzzle", sudokuGUI.filePath, sudokuGUI.fileName, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", |
From: John L. <jr...@us...> - 2006-05-30 22:56:34
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: move check stack to debug lib and remove duplicate code Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** wxluasudoku.wx.lua 30 May 2006 05:57:12 -0000 1.48 --- wxluasudoku.wx.lua 30 May 2006 22:56:29 -0000 1.49 *************** *** 165,169 **** sudoku.ELIMINATE_NAKED_QUADS = 5 -- for sudoku.CalcAllPossible(sudokuTable) sudoku.ELIMINATE_HIDDEN_QUADS = 6 -- set to true to have it run ! sudoku.FILENAME = 7 -- store the filename from Open/Save functions sudoku.ELIMINATE_FLAG_MIN = 1 -- for iterating the ELIMINATE flags --- 165,169 ---- sudoku.ELIMINATE_NAKED_QUADS = 5 -- for sudoku.CalcAllPossible(sudokuTable) sudoku.ELIMINATE_HIDDEN_QUADS = 6 -- set to true to have it run ! sudoku.FILENAME = 7 -- store the fileName from Open/Save functions sudoku.ELIMINATE_FLAG_MIN = 1 -- for iterating the ELIMINATE flags *************** *** 222,231 **** -- returns a sudoku.CreateTable() with the values set and "" on success -- or nil, error_message on failure ! function sudoku.Open(filename) local values = {} local value_count = 0 -- number of cols in line local row_count = 0 -- number of rows read local line_n = 0 -- actual line number in file ! for line in io.lines(filename) do line_n = line_n + 1 local col_count = 0 --- 222,231 ---- -- returns a sudoku.CreateTable() with the values set and "" on success -- or nil, error_message on failure ! function sudoku.Open(fileName) local values = {} local value_count = 0 -- number of cols in line local row_count = 0 -- number of rows read local line_n = 0 -- actual line number in file ! for line in io.lines(fileName) do line_n = line_n + 1 local col_count = 0 *************** *** 237,241 **** value_count = value_count + 1 else ! return nil, string.format("Error loading sudoku file : '%s' invalid number '%d' on line %d.", filename, k, line_n) end end --- 237,241 ---- value_count = value_count + 1 else ! return nil, string.format("Error loading sudoku file : '%s' invalid number '%d' on line %d.", fileName, k, line_n) end end *************** *** 244,261 **** row_count = row_count + 1 elseif (col_count ~= 0) and (col_count ~= 9) then ! return nil, string.format("Error loading sudoku file : '%s' on line %d.\nExpecting 9 columns, found %d.", filename, line_n, col_count) end end if line_n == 0 then ! return nil, string.format("Error opening sudoku file : '%s'.", filename) elseif row_count ~= 9 then ! return nil, string.format("Error loading sudoku file : '%s', expected 9 rows, found %d.", filename, row_count) elseif value_count ~= 81 then ! return nil, string.format("Error loading sudoku file : '%s', expected 81 numbers, found %d.", filename, value_count) end local s = sudoku.CreateTable() ! s.flags[sudoku.FILENAME] = filename s = sudoku.SetValues(values, s) --- 244,261 ---- row_count = row_count + 1 elseif (col_count ~= 0) and (col_count ~= 9) then ! return nil, string.format("Error loading sudoku file : '%s' on line %d.\nExpecting 9 columns, found %d.", fileName, line_n, col_count) end end if line_n == 0 then ! return nil, string.format("Error opening sudoku file : '%s'.", fileName) elseif row_count ~= 9 then ! return nil, string.format("Error loading sudoku file : '%s', expected 9 rows, found %d.", fileName, row_count) elseif value_count ~= 81 then ! return nil, string.format("Error loading sudoku file : '%s', expected 81 numbers, found %d.", fileName, value_count) end local s = sudoku.CreateTable() ! s.flags[sudoku.FILENAME] = fileName s = sudoku.SetValues(values, s) *************** *** 264,269 **** -- Save a sudoku grid as a 9x9 comma separated table to a file, returns success ! function sudoku.Save(filename, sudokuTable) ! local f = io.open(filename, "w+") if not f then return false end --- 264,269 ---- -- Save a sudoku grid as a 9x9 comma separated table to a file, returns success ! function sudoku.Save(fileName, sudokuTable) ! local f = io.open(fileName, "w+") if not f then return false end *************** *** 272,276 **** io.close(f) ! sudokuTable.flags[sudoku.FILENAME] = filename return true --- 272,276 ---- io.close(f) ! sudokuTable.flags[sudoku.FILENAME] = fileName return true *************** *** 1242,1263 **** if backwards == true then k = 10 - n end if possible[k] then ! -- try a number and remove it as a possibility ! s = sudoku.RemoveCellPossible(cell, k, s) ! -- start a new table and test out this guess w/ new table ! local s1 = sudoku.RemovePossibleAll(row, col, k, TableCopy(s)) ! local g ! -- don't use SetValue since we only care about possible ! s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) ! guesses[cell] = guesses[cell] + 1 ! guesses.current = guesses.current + 1 ! s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) ! -- if s1 then success! we're all done ! if s1 then ! local s2 = TableCopy(sudokuTable) ! s2 = sudoku.SetValues(s1.values, s2) ! return s2, g ! end end end --- 1242,1263 ---- if backwards == true then k = 10 - n end if possible[k] then ! -- try a number and remove it as a possibility ! s = sudoku.RemoveCellPossible(cell, k, s) ! -- start a new table and test out this guess w/ new table ! local s1 = sudoku.RemovePossibleAll(row, col, k, TableCopy(s)) ! local g ! -- don't use SetValue since we only care about possible ! s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) ! guesses[cell] = guesses[cell] + 1 ! guesses.current = guesses.current + 1 ! s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) ! -- if s1 then success! we're all done ! if s1 then ! local s2 = TableCopy(sudokuTable) ! s2 = sudoku.SetValues(s1.values, s2) ! return s2, g ! end end end *************** *** 1274,1290 **** end function sudoku.IsUniquePuzzle(sudokuTable) local s1, g1 = sudoku.SolveBruteForce(sudokuTable, false) ! local s2, g2 = sudoku.SolveBruteForce(sudokuTable, true) ! if (not s1) or (not s2) then return nil, g1 end ! if not sudoku.IsSamePuzzle(s1, s2) then ! return nil, g1 ! end return s1, g1 end function sudoku.IsSamePuzzle(s1, s2) for cell = 1, 81 do --- 1274,1295 ---- end + -- Does this puzzle have a unique solution. It works by trying the brute force + -- solution method iterating from low to high numbers and then from high to low. + -- This should always find if there are at least two solutions. + -- returns nil if no solution or [soln table, # guesses] for forward iteration function sudoku.IsUniquePuzzle(sudokuTable) + local s1, g1 = sudoku.SolveBruteForce(sudokuTable, false) ! if not s1 then return nil end ! local s2, g2 = sudoku.SolveBruteForce(sudokuTable, true) ! if not s2 then return nil end ! if not sudoku.IsSamePuzzle(s1, s2) then return nil end return s1, g1 end + -- Do these two puzzles have the same cell values? Returns true/false. function sudoku.IsSamePuzzle(s1, s2) for cell = 1, 81 do *************** *** 1373,1377 **** local i = 0 local count = 0 - local last_cell local soln = TableCopy(sudokuTable) local bad_cells = {} --- 1378,1381 ---- *************** *** 1393,1411 **** end ! if (not bad_cells[cell]) and (last_cell ~= cell) and sudoku.HasCellValue(cell, sudokuTable) then -- test if soln going forward is same as soln backwards and original local s = TableCopy(sudokuTable) s = sudoku.SetCellValue(cell, 0, s) local soln1 = sudoku.SolveBruteForce(s, false) if not sudoku.IsSamePuzzle(soln, soln1) then - -- don't try same cell twice in a row - last_cell = cell bad_cells[cell] = true bad_cells_count = bad_cells_count + 1 else local soln2 = sudoku.SolveBruteForce(s, true) if not sudoku.IsSamePuzzle(soln, soln2) then - last_cell = cell bad_cells[cell] = true bad_cells_count = bad_cells_count + 1 --- 1397,1415 ---- end ! if (not bad_cells[cell]) and sudoku.HasCellValue(cell, sudokuTable) then -- test if soln going forward is same as soln backwards and original local s = TableCopy(sudokuTable) s = sudoku.SetCellValue(cell, 0, s) local soln1 = sudoku.SolveBruteForce(s, false) + if not soln1 then return nil, count end if not sudoku.IsSamePuzzle(soln, soln1) then bad_cells[cell] = true bad_cells_count = bad_cells_count + 1 else local soln2 = sudoku.SolveBruteForce(s, true) + if not soln2 then return nil, count end + if not sudoku.IsSamePuzzle(soln, soln2) then bad_cells[cell] = true bad_cells_count = bad_cells_count + 1 *************** *** 1813,1817 **** ]] ! -- Simply way to generate unique window or menu ids function NewID() if not sudokuGUI_ID_New then sudokuGUI_ID_New = wx.wxID_HIGHEST end --- 1817,1821 ---- ]] ! -- Simply way to generate unique window or menu ids and ensure they're in order function NewID() if not sudokuGUI_ID_New then sudokuGUI_ID_New = wx.wxID_HIGHEST end *************** *** 1831,1841 **** block_refresh = false, ! filepath = "", -- last opened filepath ! filename = "", -- last opened filename printData = wx.wxPrintData(), pageSetupData = wx.wxPageSetupDialogData(), ! Colours = {}, -- table of colours to use, indexes below VALUE_COLOUR = 1, INIT_VALUE_COLOUR = 2, --- 1835,1845 ---- block_refresh = false, ! filePath = "", -- last opened filePath ! fileName = "", -- last opened fileName printData = wx.wxPrintData(), pageSetupData = wx.wxPageSetupDialogData(), ! Colours = {}, -- table of wxColours to use, indexes below VALUE_COLOUR = 1, INIT_VALUE_COLOUR = 2, *************** *** 2508,2512 **** event:Skip() -- we don't care who actually got this event, just use the "focused cell" ! if (sudokuGUI.focused_cell_id < 1) or (sudokuGUI.focused_cell_id > 81) then return end local key = event:GetKeyCode() --- 2512,2516 ---- event:Skip() -- we don't care who actually got this event, just use the "focused cell" ! if (sudokuGUI.focused_cell_id < 1) then return end local key = event:GetKeyCode() *************** *** 2524,2528 **** event:Skip() -- we don't care who actually got this event, just use the "focused cell" ! if (sudokuGUI.focused_cell_id < 1) or (sudokuGUI.focused_cell_id > 81) then return end local key = event:GetKeyCode() --- 2528,2532 ---- event:Skip() -- we don't care who actually got this event, just use the "focused cell" ! if (sudokuGUI.focused_cell_id < 1) then return end local key = event:GetKeyCode() *************** *** 2743,2747 **** end ! -- value is still bad, just exit if not ((value == 0) or sudoku.IsValidValueN(value)) then return end --- 2747,2751 ---- end ! -- if value is still bad, just exit if not ((value == 0) or sudoku.IsValidValueN(value)) then return end *************** *** 2788,2792 **** -- clear calculated values to save memory for n = 2, sudokuGUI.sudokuTables_pos do - sudokuGUI.sudokuTables[n].possible = {} sudokuGUI.sudokuTables[n].row_values = {} sudokuGUI.sudokuTables[n].col_values = {} --- 2792,2795 ---- *************** *** 2827,2832 **** -- Create a new empty puzzle function sudokuGUI.NewPuzzle() ! local ret = wx.wxMessageBox("Clear the current puzzle and start anew?", ! "wxLuaSudoku - new puzzle?", wx.wxOK + wx.wxCANCEL + wx.wxICON_INFORMATION, sudokuGUI.frame ) --- 2830,2836 ---- -- Create a new empty puzzle function sudokuGUI.NewPuzzle() ! local ret = wx.wxMessageBox("Clear the current puzzle and start anew?\n".. ! "Use 'Create' to enter the initial values.", ! "wxLuaSudoku - New puzzle?", wx.wxOK + wx.wxCANCEL + wx.wxICON_INFORMATION, sudokuGUI.frame ) *************** *** 2865,2871 **** if init then local ret = wx.wxMessageBox( ! "Enter values in cells to initialize the puzzle with.\n".. "Previous cell values will be overwritten.\n".. ! "Don't forget to uncheck the \"Create\" menu item or tool before playing.", "wxLuaSudoku - Initialize puzzle?", wx.wxOK + wx.wxCANCEL + wx.wxICON_INFORMATION, --- 2869,2875 ---- if init then local ret = wx.wxMessageBox( ! "Enter values in the cells to initialize the puzzle with.\n".. "Previous cell values will be overwritten.\n".. ! "Don't forget to uncheck 'Create' before playing.", "wxLuaSudoku - Initialize puzzle?", wx.wxOK + wx.wxCANCEL + wx.wxICON_INFORMATION, *************** *** 2885,2889 **** "Press Ok to correct them before continuing.\n".. "If you press cancel then don't blame me if things don't work out for you.", ! "wxLuaSudoku - Invalid initial puzzle", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, sudokuGUI.frame ) --- 2889,2893 ---- "Press Ok to correct them before continuing.\n".. "If you press cancel then don't blame me if things don't work out for you.", ! "wxLuaSudoku - Invalid initial puzzle!", wx.wxOK + wx.wxCANCEL + wx.wxICON_ERROR, sudokuGUI.frame ) *************** *** 2895,2898 **** --- 2899,2903 ---- elseif sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_MISTAKES) then sudokuGUI.sudokuSolnTable = sudokuGUI.SolveBruteForce(sudokuGUI.sudokuTables[1]) + if not sudokuGUI.sudokuSolnTable then -- try to make them correct the puzzle *************** *** 2900,2904 **** "The initial puzzle you've created cannot be or was not solved ".. "and therefore mistakes cannot be marked.\n".. ! "Press Ok to correct them before continuing.\n".. "If you press cancel then showing mistakes will be disabled.", "wxLuaSudoku - Invalid initial puzzle", --- 2905,2909 ---- "The initial puzzle you've created cannot be or was not solved ".. "and therefore mistakes cannot be marked.\n".. ! "Press Ok to continue 'Creating'.\n".. "If you press cancel then showing mistakes will be disabled.", "wxLuaSudoku - Invalid initial puzzle", *************** *** 2928,2932 **** local keep = wx.wxGetNumberFromUser("Set the difficulty of the new puzzle by clearing cells.", "Number of cell values to show", ! "wxLuaSudoku - generate puzzle?", sudokuGUI.difficulty, 1, 81, sudokuGUI.frame) --- 2933,2937 ---- local keep = wx.wxGetNumberFromUser("Set the difficulty of the new puzzle by clearing cells.", "Number of cell values to show", ! "wxLuaSudoku - Generate puzzle?", sudokuGUI.difficulty, 1, 81, sudokuGUI.frame) *************** *** 2936,2940 **** --- 2941,2948 ---- local solve_progress = 0 local start_time = os.time() + local last_time = start_time local solve_completed = true + local msg_idx = 1 + local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", *************** *** 2951,2957 **** if (solve_progress >= 1000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end ! local idx = math.floor((os.time()-start_time)/2)+1 ! if idx > sudokuGUI.sayings_n then idx = sudokuGUI.sayings_n end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[idx], count, cell) solve_completed = progressDialog:Update(solve_progress/10, msg) return solve_completed --- 2959,2967 ---- if (solve_progress >= 1000) then solve_progress = 0 end if solve_progress%10 ~= 0 then return true end ! if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then ! msg_idx = msg_idx + 1 ! last_time = os.time() ! end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[msg_idx], count, cell) solve_completed = progressDialog:Update(solve_progress/10, msg) return solve_completed *************** *** 2970,2991 **** local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 100, sudokuGUI.frame, wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! local idx = 1 -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleDifficultyHook(count, i, cell) if solve_completed == false then return false end -- canceled ! if math.floor((os.time()-start_time)/2) > 4 then ! idx = idx + 1 end ! if idx > sudokuGUI.sayings_n then idx = sudokuGUI.sayings_n end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[idx], count, cell) solve_completed = progressDialog:Update(i, msg) return solve_completed end sudokuGUI.sudokuSolnTable = TableCopy(s) local s1 = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, TableCopy(s)) --- 2980,3019 ---- local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 81 - sudokuGUI.difficulty, sudokuGUI.frame, wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! msg_idx = 1 ! last_time = os.time() ! local diff_count = 0 ! local diff_i = 0 ! local diff_cell = 0 ! -- define handler function here so it'll work w/o gui function sudoku.GeneratePuzzleDifficultyHook(count, i, cell) + diff_count = count + diff_i = i + diff_cell = cell if solve_completed == false then return false end -- canceled ! if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then ! msg_idx = msg_idx + 1 ! last_time = os.time() end ! local msg = string.format("%s\nIteration # %d, current cell %d, cells to go %d ", sudokuGUI.sayings[msg_idx], count, cell, 81-keep-i) solve_completed = progressDialog:Update(i, msg) return solve_completed end + -- hook into brute force solver to update the generate puzzle progress dialog + solve_progress = 0 + function sudoku.SolveBruteForceHook(guesses, cell) + solve_progress = solve_progress + 1 + if (solve_progress >= 1000) then solve_progress = 0 end + if solve_progress%10 ~= 0 then return true end + return sudoku.GeneratePuzzleDifficultyHook(diff_count, diff_i, diff_cell) + end + + sudokuGUI.sudokuSolnTable = TableCopy(s) local s1 = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, TableCopy(s)) *************** *** 3002,3006 **** function sudokuGUI.OpenPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Open file", ! sudokuGUI.filepath, sudokuGUI.filename, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", wx.wxOPEN + wx.wxFILE_MUST_EXIST) --- 3030,3034 ---- function sudokuGUI.OpenPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Open file", ! sudokuGUI.filePath, sudokuGUI.fileName, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", wx.wxOPEN + wx.wxFILE_MUST_EXIST) *************** *** 3008,3017 **** local fileName = fileDialog:GetPath() local fn = wx.wxFileName(fileName) ! sudokuGUI.filepath = fn:GetPath() ! sudokuGUI.filename = fn:GetFullName() local s, msg = sudoku.Open(fileName) if s then ! sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.filename) sudokuGUI.sudokuTables_pos = 1 sudokuGUI.sudokuTables = {} --- 3036,3045 ---- local fileName = fileDialog:GetPath() local fn = wx.wxFileName(fileName) ! sudokuGUI.filePath = fn:GetPath() ! sudokuGUI.fileName = fn:GetFullName() local s, msg = sudoku.Open(fileName) if s then ! sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) sudokuGUI.sudokuTables_pos = 1 sudokuGUI.sudokuTables = {} *************** *** 3063,3067 **** function sudokuGUI.SaveAsPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Save file", ! sudokuGUI.filepath, sudokuGUI.filename, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", wx.wxSAVE + wx.wxOVERWRITE_PROMPT) --- 3091,3095 ---- function sudokuGUI.SaveAsPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Save file", ! sudokuGUI.filePath, sudokuGUI.fileName, "wxLuaSudoku files (*.sudoku)|*.sudoku|All files (*)|*", wx.wxSAVE + wx.wxOVERWRITE_PROMPT) *************** *** 3070,3079 **** local fileName = fileDialog:GetPath() local fn = wx.wxFileName(fileName) ! sudokuGUI.filepath = fn:GetPath() ! sudokuGUI.filename = fn:GetFullName() result = sudoku.Save(fileName, sudokuGUI.GetCurrentGrid()) if result then ! sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.filename) else wx.wxMessageBox( "Unable to save file\n"..fileName, --- 3098,3107 ---- local fileName = fileDialog:GetPath() local fn = wx.wxFileName(fileName) ! sudokuGUI.filePath = fn:GetPath() ! sudokuGUI.fileName = fn:GetFullName() result = sudoku.Save(fileName, sudokuGUI.GetCurrentGrid()) if result then ! sudokuGUI.frame:SetTitle("wxLuaSudoku - "..sudokuGUI.fileName) else wx.wxMessageBox( "Unable to save file\n"..fileName, *************** *** 3209,3213 **** function sudokuGUI.SolveBruteForce(sudokuTable) local solve_progress = 0 - local start_time = os.time() local s = TableCopy(sudokuTable or sudokuGUI.GetCurrentGrid()) --- 3237,3240 ---- *************** *** 3250,3253 **** --- 3277,3283 ---- local solve_completed = true + local start_time = os.time() + local last_time = start_time + local msg_idx = 1 -- define handler function here so it'll work w/o gui *************** *** 3257,3263 **** if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end ! local idx = math.floor((os.time()-start_time)/2)+1 -- math.floor(count / 300) + 1 ! if idx > sudokuGUI.sayings_n then idx = sudokuGUI.sayings_n end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[idx], guesses.current, cell) solve_completed = progressDialog:Update(solve_progress/10, msg) return solve_completed --- 3287,3295 ---- if (solve_progress >= 1000) then solve_progress = 0 end if (solve_progress-1)%10 ~= 0 then return true end ! if (msg_idx < sudokuGUI.sayings_n) and (os.time() - last_time > 4) then ! msg_idx = msg_idx + 1 ! last_time = os.time() ! end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[msg_idx], guesses.current, cell) solve_completed = progressDialog:Update(solve_progress/10, msg) return solve_completed *************** *** 4018,4025 **** if read then if config:HasEntry(path.."/LastOpenedFilepath") then ! sudokuGUI.filepath = config:Read(path.."/LastOpenedFilepath") end if config:HasEntry(path.."/LastOpenedFilename") then ! sudokuGUI.filename = config:Read(path.."/LastOpenedFilename") end if config:HasEntry(path.."/GenerateDifficulty") then --- 4050,4057 ---- if read then if config:HasEntry(path.."/LastOpenedFilepath") then ! sudokuGUI.filePath = config:Read(path.."/LastOpenedFilepath") end if config:HasEntry(path.."/LastOpenedFilename") then ! sudokuGUI.fileName = config:Read(path.."/LastOpenedFilename") end if config:HasEntry(path.."/GenerateDifficulty") then *************** *** 4027,4032 **** end else ! config:Write(path.."/LastOpenedFilepath", sudokuGUI.filepath) ! config:Write(path.."/LastOpenedFilename", sudokuGUI.filename) config:WriteInt(path.."/GenerateDifficulty", sudokuGUI.difficulty) end --- 4059,4064 ---- end else ! config:Write(path.."/LastOpenedFilepath", sudokuGUI.filePath) ! config:Write(path.."/LastOpenedFilename", sudokuGUI.fileName) config:WriteInt(path.."/GenerateDifficulty", sudokuGUI.difficulty) end |
From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxlua/src Modified Files: internal.cpp wxlstate.cpp Log Message: move check stack to debug lib and remove duplicate code Index: internal.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/internal.cpp,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** internal.cpp 4 May 2006 05:07:04 -0000 1.41 --- internal.cpp 30 May 2006 22:56:29 -0000 1.42 *************** *** 390,625 **** } - // ---------------------------------------------------------------------------- - // wxLuaCheckStack - dumps the contents of the lua_State - // ---------------------------------------------------------------------------- - - wxLuaCheckStack::wxLuaCheckStack(lua_State *L, const wxString &msg) - { - m_luaState = L; - m_msg = msg; - m_top = lua_gettop(m_luaState); - } - - wxLuaCheckStack::~wxLuaCheckStack() - { - TestStack(m_msg); - } - - void wxLuaCheckStack::TestStack(const wxString &msg) - { - wxString message = msg; - - if (message.IsEmpty()) - message = 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\r\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); - } - - int wxLuaCheckStack::GetTableInfo(lua_State *L, int index, wxString& address, wxString& info) - { - int nTag = wxLua_lua_ttag(L, index); - int nItems = luaL_getn(L, index); - const void *pItem = lua_topointer(L, index); - - address = wxString::Format(wxT("%p"), pItem); - - if (nTag != TLUA_NOTAG) - { - if (nItems == 0) - info = wxString::Format(_("(tag %u)"), nTag); - else - info = wxString::Format(_("(tag %u, approx. %u items)"), nTag, nItems); - } - else - { - if (nItems == 0) - info = _("(no tag)"); - else - info = wxString::Format(_("(no tag, approx %u items)"), nItems); - } - - return nItems; - } - - // FIXME - this function copied from wxLuaDebugData to remove dependency - wxString wxLuaDebugData_MakeNumber(double dnum) - { - 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); - } - - void wxLuaCheckStack::DumpType(lua_State *L, int index, wxString& type, wxString& value, wxString& info) - { - type = wxEmptyString; - value = wxEmptyString; - info = wxEmptyString; - - switch (lua_type(L, index)) - { - default: - type = wxString::Format(wxT("%u"), lua_type(L, index)); - value = wxT("?"); - break; - - case LUA_TNIL: - type = wxT("Nil"); - value = wxT("nil"); - break; - - case LUA_TNUMBER: - type = wxT("Number"); - value = wxLuaDebugData_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"); - GetTableInfo(L, index, value, info); - break; - - case LUA_TFUNCTION: - if (lua_iscfunction(L, index)) - { - type = wxT("C Function"); - value = wxString::Format(wxT("%p"), lua_tocfunction(L, index)); - } - else - { - type = wxT("Lua Function"); - value = wxString::Format(wxT("%p"), lua_topointer(L, index)); - } - - break; - - case LUA_TUSERDATA: - type = wxT("User Data"); - value = GetUserDataInfo(L, index); - break; - } - - //return wxString::Format(_("%s - type: %s, value: %s\n"), name.c_str(), type.c_str(), value.c_str()); - } - - wxString wxLuaCheckStack::GetUserDataInfo(lua_State *L, int index) - { - wxString userdataInfo; - wxString tagName; - wxLuaState wxlState(L); - - int nTag = wxLua_lua_ttag(L, index); - - if (nTag != TLUA_NOTAG) - tagName = lua2wx(wxlState.GetLuaTagName(nTag)); - - if (!tagName.IsEmpty()) - userdataInfo = wxString::Format(wxT("%p (%s)"), lua_touserdata(L, index), tagName.c_str()); - else - userdataInfo = wxString::Format(wxT("%p (%u)"), lua_touserdata(L, index), nTag); - - return userdataInfo; - } - - void wxLuaCheckStack::DumpTable(lua_State *L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent) - { - wxString indentStr; - - if (indent > 5) - return; - - for (int i = 0; i < indent; i++) - { - indentStr += wxT(" "); - } - - wxString title = wxString::Format(wxT("%sTable: %s"), indentStr.c_str(), tablename.c_str()); - wxLogMessage(title); - - if (!indentStr.IsEmpty()) - indentStr += wxT(">"); - - lua_pushnil(L); - while(lua_next(L, index) != 0) - { - wxString indexType, indexValue, indexInfo; - wxString valueType, value, valueInfo; - - DumpType(L, -2, indexType, indexValue, indexInfo); - DumpType(L, -1, valueType, value, valueInfo); - - wxString info = wxString::Format(wxT("%s%-32s\t%-15s\t%-20s\t%-10s\t%s"), - indentStr.c_str(), - indexValue.c_str(), - indexType.c_str(), - valueType.c_str(), - value.c_str(), - valueInfo.c_str()); - wxLogMessage(info); - - if (dumpList.find(value) != dumpList.end()) - { - if (valueType == wxT("Table")) - { - wxString tname = wxString::Format(wxT("%s.%s"), tablename.c_str(), indexValue.c_str()); - - dumpList[value] = 1; - - int tableIndex = lua_gettop(L); - - // lua_pushvalue(L, lua_gettop(L)); - DumpTable(L, tableIndex, tname, dumpList, indent+1); - } - else - { - dumpList[value] = 1; - } - } - - //#if defined(__WXMSW__) - // OutputDebugString(outputIndex + outputValue); - //#elif defined(__WXGTK__) - // fprintf(stderr, wx2lua(outputIndex + outputValue)); - //#endif - lua_pop(L, 1); - } - lua_pop(L, 1); - - wxLog::FlushActive(); - } // Validate that the object at the stack index specified is a string object --- 390,393 ---- Index: wxlstate.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/src/wxlstate.cpp,v retrieving revision 1.70 retrieving revision 1.71 diff -C2 -d -r1.70 -r1.71 *** wxlstate.cpp 25 May 2006 03:55:23 -0000 1.70 --- wxlstate.cpp 30 May 2006 22:56:29 -0000 1.71 *************** *** 63,70 **** extern "C" { - #include "lua/include/lua.h" - #include "lua/include/lauxlib.h" - #include "lua/include/lualib.h" - #ifdef WXLUA_LUA_NEWTHREAD // See lua/src/lstate.c for added hook into luaE_newthread() --- 63,66 ---- |
From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxluadebug/src Modified Files: wxldebug.cpp Log Message: move check stack to debug lib and remove duplicate code Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** wxldebug.cpp 25 May 2006 22:50:05 -0000 1.14 --- wxldebug.cpp 30 May 2006 22:56:29 -0000 1.15 *************** *** 24,27 **** --- 24,28 ---- #include "wxluadebug/include/wxldebug.h" + #include "wxlua/include/internal.h" // ---------------------------------------------------------------------------- *************** *** 297,301 **** case LUA_TUSERDATA: type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, index); break; --- 298,302 ---- case LUA_TUSERDATA: type = wxT("User Data"); ! value = GetUserDataInfo(wxlState, index, true); break; *************** *** 337,343 **** --- 338,354 ---- wxCHECK_MSG(wxlState.Ok(), wxEmptyString, wxT("Invalid wxLuaState")); lua_State* L = wxlState.GetLuaState(); + + int nTag = wxLua_lua_ttag(L, index); int nItems = luaL_getn(L, index); const void *pItem = lua_topointer(L, index); + if (nTag != TLUA_NOTAG) + { + if (nItems == 0) + return wxString::Format(wxT("0x%p (tag %u)"), pItem, nTag); + + return wxString::Format(wxT("0x%p (approx %u items) (tag %u)"), pItem, nItems, nTag); + } + if (nItems == 0) return wxString::Format(wxT("0x%p"), pItem); *************** *** 355,364 **** int nTag = wxlState.ttag(index); ! const char *pTagName = NULL; if (nTag != TLUA_NOTAG) ! pTagName = wxlState.GetLuaTagName(nTag); ! if (pTagName != NULL) ! return wxString::Format(wxT("0x%p (%s)"), lua_touserdata(L, index), lua2wx(pTagName).c_str()); return wxString::Format(wxT("0x%p (%u)"), lua_touserdata(L, index), nTag); --- 366,375 ---- int nTag = wxlState.ttag(index); ! wxString pTagName; if (nTag != TLUA_NOTAG) ! pTagName = lua2wx(wxlState.GetLuaTagName(nTag)); ! if (!pTagName.IsEmpty()) ! return wxString::Format(wxT("0x%p (%s)"), lua_touserdata(L, index), pTagName.c_str()); return wxString::Format(wxT("0x%p (%u)"), lua_touserdata(L, index), nTag); *************** *** 431,432 **** --- 442,552 ---- return pSortedList; } + + // ---------------------------------------------------------------------------- + // wxLuaCheckStack - dumps the contents of the lua_State + // ---------------------------------------------------------------------------- + + wxLuaCheckStack::wxLuaCheckStack(lua_State *L, const wxString &msg) + { + m_luaState = L; + m_msg = msg; + m_top = lua_gettop(m_luaState); + } + + wxLuaCheckStack::~wxLuaCheckStack() + { + TestStack(m_msg); + } + + void wxLuaCheckStack::TestStack(const wxString &msg) + { + 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; + + if (indent > 5) + return; + + for (int i = 0; i < indent; i++) + indentStr += wxT(" "); + + wxString title = wxString::Format(wxT("%sTable: %s"), indentStr.c_str(), tablename.c_str()); + wxLogMessage(title); + + if (!indentStr.IsEmpty()) + indentStr += wxT(">"); + + lua_pushnil(L); + while(lua_next(L, index) != 0) + { + wxString indexType, indexValue; + wxString valueType, value; + + wxLuaDebugData::GetTypeValue(wxlState, -2, indexType, indexValue); + wxLuaDebugData::GetTypeValue(wxlState, -1, valueType, value); + + wxString info = wxString::Format(wxT("%s%-32s\t%-15s\t%-20s\t%-10s"), + indentStr.c_str(), + indexValue.c_str(), + indexType.c_str(), + valueType.c_str(), + value.c_str()); + wxLogMessage(info); + + if (dumpList.find(value) != dumpList.end()) + { + if (valueType == wxT("Table")) + { + wxString tname = wxString::Format(wxT("%s.%s"), tablename.c_str(), indexValue.c_str()); + dumpList[value] = 1; + int tableIndex = lua_gettop(L); + // lua_pushvalue(L, lua_gettop(L)); + DumpTable(L, tableIndex, tname, dumpList, indent+1); + } + else + { + dumpList[value] = 1; + } + } + + //#if defined(__WXMSW__) + // OutputDebugString(outputIndex + outputValue); + //#elif defined(__WXGTK__) + // fprintf(stderr, wx2lua(outputIndex + outputValue)); + //#endif + lua_pop(L, 1); + } + lua_pop(L, 1); + + wxLog::FlushActive(); + } |
From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxlua/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxlua/include Modified Files: internal.h Log Message: move check stack to debug lib and remove duplicate code Index: internal.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxlua/include/internal.h,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** internal.h 20 May 2006 19:40:19 -0000 1.30 --- internal.h 30 May 2006 22:56:28 -0000 1.31 *************** *** 176,203 **** WXDLLIMPEXP_WXLUA void LUACALL wxLua_lua_tpushwxLuaNull(lua_State* L); - // ---------------------------------------------------------------------------- - // wxLuaCheckStack - dumps the contents of the lua_State - // ---------------------------------------------------------------------------- - - class WXDLLIMPEXP_WXLUA wxLuaCheckStack - { - public: - wxLuaCheckStack(lua_State* L, const wxString &msg); - ~wxLuaCheckStack(); - void TestStack(const wxString &msg); - - static void DumpGlobals(lua_State* L); - static void DumpTable(lua_State* L, const wxString &tableName); - static void DumpTable(lua_State* L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent); - - private: - static void DumpType(lua_State* L, int index, wxString& type, wxString& value, wxString& info); - static int GetTableInfo(lua_State* L, int index, wxString& address, wxString& info); - static wxString GetUserDataInfo(lua_State* L, int index); - - lua_State* m_luaState; - wxString m_msg; - int m_top; - }; - #endif // WX_LUA_INTERNALS_H --- 176,178 ---- |
From: John L. <jr...@us...> - 2006-05-30 22:56:33
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv15712/wxLua/modules/wxluadebug/include Modified Files: wxldebug.h Log Message: move check stack to debug lib and remove duplicate code Index: wxldebug.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/include/wxldebug.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** wxldebug.h 20 May 2006 19:57:59 -0000 1.16 --- wxldebug.h 30 May 2006 22:56:29 -0000 1.17 *************** *** 135,137 **** --- 135,158 ---- }; + // ---------------------------------------------------------------------------- + // wxLuaCheckStack - dumps the contents of the lua_State + // ---------------------------------------------------------------------------- + + class WXDLLIMPEXP_WXLUA wxLuaCheckStack + { + public: + wxLuaCheckStack(lua_State* L, const wxString &msg); + ~wxLuaCheckStack(); + void TestStack(const wxString &msg); + + static void DumpGlobals(lua_State* L); + static void DumpTable(lua_State* L, const wxString &tableName); + static void DumpTable(lua_State* L, int index, const wxString& tablename, wxLuaStringToLongHashMap& dumpList, int indent); + + private: + lua_State* m_luaState; + wxString m_msg; + int m_top; + }; + #endif // WX_LUA_DEBUG_H |
From: John L. <jr...@us...> - 2006-05-30 05:57:15
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv30914/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: first cut at generating unique puzzles Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** wxluasudoku.wx.lua 25 May 2006 03:55:23 -0000 1.47 --- wxluasudoku.wx.lua 30 May 2006 05:57:12 -0000 1.48 *************** *** 588,595 **** -- if exceptTable then don't remove it from exceptTable[cell#] = true function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable) -- cell will be done below, note it's not any faster to code it all here ! sudokuTable = sudoku.RemovePossibleRow(row, value, sudokuTable, exceptTable) ! sudokuTable = sudoku.RemovePossibleCol(col, value, sudokuTable, exceptTable) ! sudokuTable = sudoku.RemovePossibleBlock(sudoku.RowColToBlock(row, col), value, sudokuTable, exceptTable) return sudokuTable end --- 588,616 ---- -- if exceptTable then don't remove it from exceptTable[cell#] = true function sudoku.RemovePossibleAll(row, col, value, sudokuTable, exceptTable) + exceptTable = exceptTable or {} + local cell + local block_cell = sudoku.BlockToCell(sudoku.RowColToBlock(row, col)) + + for rcb = 1, 9 do + cell = sudoku.RowColToCell(rcb, col) + if not exceptTable[cell] then + sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) + end + + cell = sudoku.RowColToCell(row, rcb) + if not exceptTable[cell] then + sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) + end + + cell = rcb - 1 + block_cell + sudoku.LinearBlockCells[rcb] + if not exceptTable[cell] then + sudokuTable = sudoku.RemoveCellPossible(cell, value, sudokuTable) + end + end + -- cell will be done below, note it's not any faster to code it all here ! --sudokuTable = sudoku.RemovePossibleRow(row, value, sudokuTable, exceptTable) ! --sudokuTable = sudoku.RemovePossibleCol(col, value, sudokuTable, exceptTable) ! --sudokuTable = sudoku.RemovePossibleBlock(sudoku.RowColToBlock(row, col), value, sudokuTable, exceptTable) return sudokuTable end *************** *** 1183,1206 **** -- Brute force recursive solver -- (call with only the SudokuTable, don't enter other parameters) ! function sudoku.SolveBruteForce(sudokuTable, simpleTable, guesses, cell) ! cell = cell or 1 ! local s = simpleTable ! -- first time through find possible to limit choices, subsequent calls ok ! if not s then ! s = sudoku.CreateTable() ! s = sudoku.SetValues(sudokuTable.values, s) ! -- table consists of guesses[cell] = #num ! -- guesses.current is current guess # ! guesses = { current = 0 } ! for n = 1, 81 do guesses[n] = 0 end ! -- we don't need these for this and they just slow TableCopy down ! -- they're recreated at the end using UpdateTable ! s.row_values = nil ! s.col_values = nil ! s.block_values = nil ! s.invalid = nil ! s.flags = nil ! end if sudoku.SolveBruteForceHook then --- 1204,1228 ---- -- Brute force recursive solver -- (call with only the SudokuTable, don't enter other parameters) ! function sudoku.SolveBruteForce(sudokuTable, backwards) -- first time through find possible to limit choices, subsequent calls ok ! local s = sudoku.CreateTable() ! s = sudoku.SetValues(sudokuTable.values, s) ! -- table consists of guesses[cell] = #num ! -- guesses.current is current guess # ! local guesses = { current = 0 } ! for n = 1, 81 do guesses[n] = 0 end ! -- we don't need these for this and they just slow TableCopy down ! -- they're recreated at the end using UpdateTable ! s.row_values = nil ! s.col_values = nil ! s.block_values = nil ! s.invalid = nil ! s.flags = nil ! ! return sudoku.DoSolveBruteForce(sudokuTable, backwards, s, guesses, 1) ! end ! ! function sudoku.DoSolveBruteForce(sudokuTable, backwards, simpleTable, guesses, cell) ! local s = simpleTable if sudoku.SolveBruteForceHook then *************** *** 1215,1219 **** local possible = sudoku.GetCellPossible(cell, s) ! for k, v in pairs(possible) do -- try a number and remove it as a possibility s = sudoku.RemoveCellPossible(cell, k, s) --- 1237,1245 ---- local possible = sudoku.GetCellPossible(cell, s) ! --for k, v in pairs(possible) do ! for n = 1, 9 do ! local k = n ! if backwards == true then k = 10 - n end ! if possible[k] then -- try a number and remove it as a possibility s = sudoku.RemoveCellPossible(cell, k, s) *************** *** 1225,1231 **** -- don't use SetValue since we only care about possible s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) ! guesses[cell] = guesses[cell] + 1 guesses.current = guesses.current + 1 ! s1, g = sudoku.SolveBruteForce(sudokuTable, s1, guesses, cell+1) -- if s1 then success! we're all done if s1 then --- 1251,1257 ---- -- don't use SetValue since we only care about possible s1.values[cell] = k --sudoku.SetValue(row, col, k, s1) ! guesses[cell] = guesses[cell] + 1 guesses.current = guesses.current + 1 ! s1, g = sudoku.DoSolveBruteForce(sudokuTable, backwards, s1, guesses, cell+1) -- if s1 then success! we're all done if s1 then *************** *** 1234,1237 **** --- 1260,1264 ---- return s2, g end + end end *************** *** 1247,1250 **** --- 1274,1300 ---- end + function sudoku.IsUniquePuzzle(sudokuTable) + local s1, g1 = sudoku.SolveBruteForce(sudokuTable, false) + local s2, g2 = sudoku.SolveBruteForce(sudokuTable, true) + + if (not s1) or (not s2) then return nil, g1 end + + if not sudoku.IsSamePuzzle(s1, s2) then + return nil, g1 + end + + return s1, g1 + end + + function sudoku.IsSamePuzzle(s1, s2) + for cell = 1, 81 do + if sudoku.GetCellValue(cell, s1) ~= sudoku.GetCellValue(cell, s2) then + return false + end + end + + return true + end + -- ============================================================================ -- Create a full puzzle with all the values *************** *** 1322,1335 **** math.randomseed(os.time()+1) local i = 0 while i < 81 - num_cells_to_keep do local cell = math.random(81) ! if sudoku.HasCellValue(cell, sudokuTable) then ! sudokuTable = sudoku.SetCellValue(cell, 0, sudokuTable) ! i = i + 1 end end ! return sudokuTable end --- 1372,1422 ---- math.randomseed(os.time()+1) local i = 0 + local count = 0 + local last_cell + local soln = TableCopy(sudokuTable) + local bad_cells = {} + local bad_cells_count = 0 while i < 81 - num_cells_to_keep do local cell = math.random(81) ! count = count + 1 ! ! if sudoku.GeneratePuzzleDifficultyHook then ! if not sudoku.GeneratePuzzleDifficultyHook(count, i, cell) then ! return nil, count ! end ! end ! ! -- recursively call this function to restart finding unique soln ! if bad_cells_count > i then ! return sudoku.GeneratePuzzleDifficulty(num_cells_to_keep, sudokuTable) ! end ! ! if (not bad_cells[cell]) and (last_cell ~= cell) and sudoku.HasCellValue(cell, sudokuTable) then ! -- test if soln going forward is same as soln backwards and original ! local s = TableCopy(sudokuTable) ! s = sudoku.SetCellValue(cell, 0, s) ! local soln1 = sudoku.SolveBruteForce(s, false) ! ! if not sudoku.IsSamePuzzle(soln, soln1) then ! -- don't try same cell twice in a row ! last_cell = cell ! bad_cells[cell] = true ! bad_cells_count = bad_cells_count + 1 ! else ! local soln2 = sudoku.SolveBruteForce(s, true) ! if not sudoku.IsSamePuzzle(soln, soln2) then ! last_cell = cell ! bad_cells[cell] = true ! bad_cells_count = bad_cells_count + 1 ! else ! sudokuTable = sudoku.SetCellValue(cell, 0, sudokuTable) ! i = i + 1 ! end ! end end end ! return sudokuTable, count end *************** *** 2849,2852 **** --- 2936,2940 ---- local solve_progress = 0 local start_time = os.time() + local solve_completed = true local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Generating...", *************** *** 2856,2860 **** wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) - local solve_completed = true -- define handler function here so it'll work w/o gui --- 2944,2947 ---- *************** *** 2875,2884 **** progressDialog:Destroy() ! if s then ! sudokuGUI.sudokuSolnTable = TableCopy(s) ! s = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, s) sudokuGUI.sudokuTables_pos = 1 sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s) sudokuGUI.UpdateTable() -- resets possible and refreshes too end --- 2962,2999 ---- progressDialog:Destroy() ! if not s then return end ! ! local solve_progress = 0 ! local start_time = os.time() ! local solve_completed = true ! ! local progressDialog = wx.wxProgressDialog("wxLuaSudoku - Ensuring Uniqueness...", ! string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[1], 0, 0), ! 100, ! sudokuGUI.frame, ! wx.wxPD_AUTO_HIDE+wx.wxPD_CAN_ABORT+wx.wxPD_ELAPSED_TIME) ! ! local idx = 1 ! ! -- define handler function here so it'll work w/o gui ! function sudoku.GeneratePuzzleDifficultyHook(count, i, cell) ! if solve_completed == false then return false end -- canceled ! if math.floor((os.time()-start_time)/2) > 4 then ! idx = idx + 1 ! end ! if idx > sudokuGUI.sayings_n then idx = sudokuGUI.sayings_n end ! local msg = string.format("%s\nIteration # %d, current cell %d ", sudokuGUI.sayings[idx], count, cell) ! solve_completed = progressDialog:Update(i, msg) ! return solve_completed ! end ! ! sudokuGUI.sudokuSolnTable = TableCopy(s) ! local s1 = sudoku.GeneratePuzzleDifficulty(sudokuGUI.difficulty, TableCopy(s)) ! progressDialog:Destroy() ! ! if s1 then sudokuGUI.sudokuTables_pos = 1 sudokuGUI.sudokuTables = {} ! table.insert(sudokuGUI.sudokuTables, s1) sudokuGUI.UpdateTable() -- resets possible and refreshes too end *************** *** 3151,3159 **** -- "cheat" a little by using SolveScan to get easy to find values local flags = TableCopy(s.flags) ! for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! s.flags[n] = true ! end ! local s, count, changed_cells = sudoku.SolveScan(s) local s, g = sudoku.SolveBruteForce(s) --- 3266,3274 ---- -- "cheat" a little by using SolveScan to get easy to find values local flags = TableCopy(s.flags) ! --for n = sudoku.ELIMINATE_FLAG_MIN, sudoku.ELIMINATE_FLAG_MAX do ! -- s.flags[n] = true ! --end ! --local s, count, changed_cells = sudoku.SolveScan(s) local s, g = sudoku.SolveBruteForce(s) |
From: John L. <jr...@us...> - 2006-05-29 22:59:59
|
Update of /cvsroot/wxlua/wxLua/bindings In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19007/wxLua/bindings Modified Files: genwxbind.lua Log Message: shuffle header includes for bindings fix double to int warning in wxEvtHandler::Connect and Disconnect Index: genwxbind.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/genwxbind.lua,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** genwxbind.lua 25 May 2006 22:50:04 -0000 1.69 --- genwxbind.lua 29 May 2006 22:31:17 -0000 1.70 *************** *** 3888,3895 **** table.insert(fileData, "#ifndef __HOOK_WXLUA_"..hook_cpp_namespace.."_H__\n") table.insert(fileData, "#define __HOOK_WXLUA_"..hook_cpp_namespace.."_H__\n\n") - table.insert(fileData, "#include \"wxlua/include/internal.h\"\n\n") table.insert(fileData, (hook_cpp_binding_header_includes or "").."\n") if hook_bind_condition then table.insert(fileData, "#if "..hook_bind_condition.."\n\n") --- 3888,3898 ---- table.insert(fileData, "#ifndef __HOOK_WXLUA_"..hook_cpp_namespace.."_H__\n") table.insert(fileData, "#define __HOOK_WXLUA_"..hook_cpp_namespace.."_H__\n\n") table.insert(fileData, (hook_cpp_binding_header_includes or "").."\n") + table.insert(fileData, "#include \"wxlua/include/wxlstate.h\"\n") + table.insert(fileData, "#include \"wxlua/include/wxlbind.h\"\n") + table.insert(fileData, "#include \"wxlua/include/internal.h\"\n\n") + if hook_bind_condition then table.insert(fileData, "#if "..hook_bind_condition.."\n\n") |
From: John L. <jr...@us...> - 2006-05-29 22:57:02
|
Update of /cvsroot/wxlua/wxLua/bindings/wxwidgets In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19007/wxLua/bindings/wxwidgets Modified Files: override.hpp Log Message: shuffle header includes for bindings fix double to int warning in wxEvtHandler::Connect and Disconnect Index: override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/override.hpp,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** override.hpp 26 May 2006 20:22:09 -0000 1.49 --- override.hpp 29 May 2006 22:31:17 -0000 1.50 *************** *** 1763,1767 **** if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); else { --- 1763,1767 ---- if (wxlState.IsNumberType(evttype_idx)) ! eventType = (int)lua_tonumber(L, evttype_idx); else { *************** *** 1853,1857 **** if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); else { --- 1853,1857 ---- if (wxlState.IsNumberType(evttype_idx)) ! eventType = (int)lua_tonumber(L, evttype_idx); else { |
From: John L. <jr...@us...> - 2006-05-29 22:57:00
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19007/wxLua/modules/wxbind/src Modified Files: event.cpp Log Message: shuffle header includes for bindings fix double to int warning in wxEvtHandler::Connect and Disconnect Index: event.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/event.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** event.cpp 25 May 2006 22:50:05 -0000 1.21 --- event.cpp 29 May 2006 22:31:17 -0000 1.22 *************** *** 177,181 **** if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); else { --- 177,181 ---- if (wxlState.IsNumberType(evttype_idx)) ! eventType = (int)lua_tonumber(L, evttype_idx); else { *************** *** 266,270 **** if (wxlState.IsNumberType(evttype_idx)) ! eventType = lua_tonumber(L, evttype_idx); else { --- 266,270 ---- if (wxlState.IsNumberType(evttype_idx)) ! eventType = (int)lua_tonumber(L, evttype_idx); else { |
From: John L. <jr...@us...> - 2006-05-29 22:57:00
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19007/wxLua/modules/wxbind/include Modified Files: wxbind.h Log Message: shuffle header includes for bindings fix double to int warning in wxEvtHandler::Connect and Disconnect Index: wxbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/include/wxbind.h,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** wxbind.h 26 May 2006 20:22:14 -0000 1.32 --- wxbind.h 29 May 2006 22:31:17 -0000 1.33 *************** *** 9,14 **** #define __HOOK_WXLUA_wx_H__ - #include "wxlua/include/internal.h" - #include "wx/defs.h" #include "wxluasetup.h" --- 9,12 ---- *************** *** 21,24 **** --- 19,26 ---- #endif + #include "wxlua/include/wxlstate.h" + #include "wxlua/include/wxlbind.h" + #include "wxlua/include/internal.h" + // binding class class wxLuaBinding_wx : public wxLuaBinding |
From: John L. <jr...@us...> - 2006-05-26 20:22:25
|
Update of /cvsroot/wxlua/wxLua/bindings/wxwidgets In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10865/wxLua/bindings/wxwidgets Modified Files: controls.i data.i override.hpp wx_datatypes.lua Log Message: add wxArrayTreeItemIds and hack for wxTreeItemIdValue Index: wx_datatypes.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wx_datatypes.lua,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** wx_datatypes.lua 25 May 2006 22:50:05 -0000 1.33 --- wx_datatypes.lua 26 May 2006 20:22:09 -0000 1.34 *************** *** 223,226 **** --- 223,232 ---- Name = "wxArrayString_FromLuaTable", }, + wxArrayTreeItemIds = { + Condition = "wxLUA_USE_wxTreeCtrl", + DefType = "class", + Intrinsic = false, + Name = "wxArrayTreeItemIds", + }, wxArtProvider = { BaseClass = "wxObject", *************** *** 2916,2922 **** }, wxTreeItemIdValue = { ! Condition = "(wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl)", ! DefType = "class", ! Intrinsic = false, Name = "wxTreeItemIdValue", }, --- 2922,2928 ---- }, wxTreeItemIdValue = { ! Condition = "wxLUA_USE_wxTreeCtrl", ! DefType = "enum", ! Intrinsic = true, Name = "wxTreeItemIdValue", }, Index: data.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/data.i,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** data.i 26 May 2006 03:19:51 -0000 1.17 --- data.i 26 May 2006 20:22:09 -0000 1.18 *************** *** 248,255 **** --- 248,257 ---- //%class %noclassinfo wxArray // // no constructor since this class doesn't exist + // void Add(T &item, size_t copies = 1) // void Alloc(size_t count) // void Clear() // void Empty() // int GetCount() const + // void Insert(T &item, size_t n, size_t copies = 1) // bool IsEmpty() const // void RemoveAt(size_t index, size_t count = 1) Index: override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/override.hpp,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** override.hpp 26 May 2006 03:19:51 -0000 1.48 --- override.hpp 26 May 2006 20:22:09 -0000 1.49 *************** *** 858,862 **** wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); #if wxCHECK_VERSION(2, 5, 0) ! wxlState.PushUserDataType(s_wxluatag_wxTreeItemIdValue, cookie); #else // push the cookie --- 858,862 ---- wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); #if wxCHECK_VERSION(2, 5, 0) ! lua_pushnumber(L, (long)cookie); // wxTreeItemIdValue is void* #else // push the cookie *************** *** 876,880 **** #if wxCHECK_VERSION(2, 5, 0) ! wxTreeItemIdValue cookie = (wxTreeItemIdValue *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeItemIdValue); #else // long& cookie --- 876,880 ---- #if wxCHECK_VERSION(2, 5, 0) ! wxTreeItemIdValue cookie = (wxTreeItemIdValue)(long)wxlState.GetNumberType(3); #else // long& cookie *************** *** 893,897 **** wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); #if wxCHECK_VERSION(2, 5, 0) ! wxlState.PushUserDataType(s_wxluatag_wxTreeItemIdValue, cookie); #else // push the cookie --- 893,897 ---- wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); #if wxCHECK_VERSION(2, 5, 0) ! lua_pushnumber(L, (long)cookie); #else // push the cookie Index: controls.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/controls.i,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** controls.i 26 May 2006 03:19:51 -0000 1.21 --- controls.i 26 May 2006 20:22:09 -0000 1.22 *************** *** 1178,1189 **** // wxTreeItemIdValue - wxTreeCtrl ! %if %wxchkver25 ! %class %noclassinfo wxTreeItemIdValue ! %endclass ! %endif //----------------------------------------------------------------------------- // wxTreeItemId - wxTreeCtrl %class %delete %noclassinfo %encapsulate wxTreeItemId %overload wxTreeItemId() --- 1178,1194 ---- // wxTreeItemIdValue - wxTreeCtrl ! //%if %wxchkver25 ! //%class %noclassinfo wxTreeItemIdValue ! //%endclass ! //%endif //----------------------------------------------------------------------------- // wxTreeItemId - wxTreeCtrl + %enum wxTreeItemIdValue + // FAKE enum, actually typedef void* wxTreeItemIdValue + // but lua only uses double. This gets around compiler errors/warnings + %endenum + %class %delete %noclassinfo %encapsulate wxTreeItemId %overload wxTreeItemId() *************** *** 1191,1195 **** bool IsOk() ! long GetValue() const // get a pointer to the internal data to use as a reference in a lua table %operator wxTreeItemId& operator=(const wxTreeItemId& otherId) --- 1196,1200 ---- bool IsOk() ! wxTreeItemIdValue GetValue() const // get a pointer to the internal data to use as a reference in a lua table %operator wxTreeItemId& operator=(const wxTreeItemId& otherId) *************** *** 1200,1203 **** --- 1205,1237 ---- //----------------------------------------------------------------------------- + // wxArrayTreeItemIds - wxTreeCtrl + // Note: This is actually an array of the internal wxTreeItemIdValue data + // which is a void* pointer. This is why we use long. + // See wxLua's wxTreeItemId::GetValue() function + + %class %delete %noclassinfo %encapsulate wxArrayTreeItemIds + %overload wxArrayTreeItemIds() + %overload %constructor wxArrayTreeItemIdsCopy(const wxArrayTreeItemIds& array) + //%overload %constructor wxArrayStringFromTable(const wxArrayString_FromLuaTable& array) + + // %override [lua table] wxArrayString::ToLuaTable() const + //int ToLuaTable() const + + void Add(const wxTreeItemId& id) + void Alloc(size_t nCount) + void Clear() + void Empty() + int GetCount() const + int Index(wxTreeItemIdValue treeItemIdValue, bool bFromEnd = false) + //void Insert(wxTreeItemId& str, int nIndex, size_t copies = 1) + bool IsEmpty() + wxTreeItemId Item(size_t nIndex) const + wxTreeItemId Last() + void Remove(wxTreeItemIdValue treeItemIdValue) + void RemoveAt(size_t nIndex, size_t count = 1) + void Shrink() + %endclass + + //----------------------------------------------------------------------------- // wxTreeItemData - wxTreeCtrl, see also wxLuaTreeItemData |
From: John L. <jr...@us...> - 2006-05-26 20:22:22
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10865/wxLua/modules/wxbind/src Modified Files: controls.cpp wx_bind.cpp Log Message: add wxArrayTreeItemIds and hack for wxTreeItemIdValue Index: wx_bind.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/wx_bind.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** wx_bind.cpp 25 May 2006 22:50:05 -0000 1.44 --- wx_bind.cpp 26 May 2006 20:22:15 -0000 1.45 *************** *** 5359,5367 **** - #if (wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl) - { "wxTreeItemIdValue", wxTreeItemIdValue_methods, wxTreeItemIdValue_methodCount, -1, NULL, &s_wxluatag_wxTreeItemIdValue, NULL }, - #endif - - #if (wxLUA_USE_wxBitmapButton) && (wxLUA_USE_wxButton) { "wxBitmapButton", wxBitmapButton_methods, wxBitmapButton_methodCount, -1, CLASSINFO(wxBitmapButton), &s_wxluatag_wxBitmapButton, "wxButton" }, --- 5359,5362 ---- *************** *** 6197,6200 **** --- 6192,6196 ---- #if wxLUA_USE_wxTreeCtrl + { "wxArrayTreeItemIds", wxArrayTreeItemIds_methods, wxArrayTreeItemIds_methodCount, -1, NULL, &s_wxluatag_wxArrayTreeItemIds, NULL }, { "wxLuaTreeItemData", wxLuaTreeItemData_methods, wxLuaTreeItemData_methodCount, -1, NULL, &s_wxluatag_wxLuaTreeItemData, "wxTreeItemData" }, { "wxTreeCtrl", wxTreeCtrl_methods, wxTreeCtrl_methodCount, -1, CLASSINFO(wxTreeCtrl), &s_wxluatag_wxTreeCtrl, "wxControl" }, *************** *** 6513,6516 **** --- 6509,6513 ---- #if wxLUA_USE_wxTreeCtrl + wxLUA_IMPLEMENT_ENCAPSULATION(wxArrayTreeItemIds) wxLUA_IMPLEMENT_ENCAPSULATION(wxTreeItemId) #endif Index: controls.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/controls.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** controls.cpp 26 May 2006 03:19:51 -0000 1.28 --- controls.cpp 26 May 2006 20:22:15 -0000 1.29 *************** *** 8460,8534 **** - #if ((wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl)) && (wxLUA_USE_wxTreeCtrl) - // %override wxLua_wxTreeCtrl_GetFirstChild - // wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const - static int LUACALL wxLua_wxTreeCtrl_GetFirstChild(lua_State *L) - { - wxLuaState wxlState(L); - wxTreeItemId *returns; - #if wxCHECK_VERSION(2, 5, 0) - wxTreeItemIdValue cookie = 0; - #else - // long& cookie - long cookie = 0; - #endif - // const wxTreeItemId& item - const wxTreeItemId *item = (wxTreeItemId *)wxlState.GetUserDataType(2, s_wxluatag_wxTreeItemId); - // get this - wxTreeCtrl *self = (wxTreeCtrl *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeCtrl); - // call GetFirstChild - // allocate a new object using the copy constructor - returns = new wxTreeItemId(self->GetFirstChild(*item, cookie)); - // add the new object to the tracked memory list - wxLua_AddToTrackedMemoryList(wxlState, returns); - // push the result datatype - wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); - #if wxCHECK_VERSION(2, 5, 0) - wxlState.PushUserDataType(s_wxluatag_wxTreeItemIdValue, cookie); - #else - // push the cookie - lua_pushnumber(L, cookie); - #endif - // return the number of parameters - return 2; - } - - // %override wxLua_wxTreeCtrl_GetNextChild - // wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const - static int LUACALL wxLua_wxTreeCtrl_GetNextChild(lua_State *L) - { - wxLuaState wxlState(L); - wxTreeItemId *returns; - - #if wxCHECK_VERSION(2, 5, 0) - wxTreeItemIdValue cookie = (wxTreeItemIdValue *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeItemIdValue); - #else - // long& cookie - long cookie = (long)lua_tonumber(L, 3); - #endif - // const wxTreeItemId& item - const wxTreeItemId *item = (wxTreeItemId *)wxlState.GetUserDataType(2, s_wxluatag_wxTreeItemId); - // get this - wxTreeCtrl *self = (wxTreeCtrl *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeCtrl); - // call GetNextChild - // allocate a new object using the copy constructor - returns = new wxTreeItemId(self->GetNextChild(*item, cookie)); - // add the new object to the tracked memory list - wxLua_AddToTrackedMemoryList(wxlState, returns); - // push the result datatype - wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); - #if wxCHECK_VERSION(2, 5, 0) - wxlState.PushUserDataType(s_wxluatag_wxTreeItemIdValue, cookie); - #else - // push the cookie - lua_pushnumber(L, cookie); - #endif - // return the number of parameters - return 2; - } - - #endif - - #if ((wxLUA_USE_wxTreeCtrl) && (wxLUA_USE_wxValidator)) && (wxLUA_USE_wxPointSizeRect) // wxTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_DEFAULT_STYLE, const wxValidator& validator = wxDefaultValidator, const wxString& name = "wxTreeCtrl") --- 8460,8463 ---- *************** *** 9097,9100 **** --- 9026,9062 ---- } + // %override wxLua_wxTreeCtrl_GetFirstChild + // wxTreeItemId GetFirstChild(const wxTreeItemId& item, long& cookie) const + static int LUACALL wxLua_wxTreeCtrl_GetFirstChild(lua_State *L) + { + wxLuaState wxlState(L); + wxTreeItemId *returns; + #if wxCHECK_VERSION(2, 5, 0) + wxTreeItemIdValue cookie = 0; + #else + // long& cookie + long cookie = 0; + #endif + // const wxTreeItemId& item + const wxTreeItemId *item = (wxTreeItemId *)wxlState.GetUserDataType(2, s_wxluatag_wxTreeItemId); + // get this + wxTreeCtrl *self = (wxTreeCtrl *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeCtrl); + // call GetFirstChild + // allocate a new object using the copy constructor + returns = new wxTreeItemId(self->GetFirstChild(*item, cookie)); + // add the new object to the tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, returns); + // push the result datatype + wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); + #if wxCHECK_VERSION(2, 5, 0) + lua_pushnumber(L, (long)cookie); // wxTreeItemIdValue is void* + #else + // push the cookie + lua_pushnumber(L, cookie); + #endif + // return the number of parameters + return 2; + } + // wxTreeItemId GetFirstVisibleItem() const static int LUACALL wxLua_wxTreeCtrl_GetFirstVisibleItem(lua_State *L) *************** *** 9205,9208 **** --- 9167,9204 ---- } + // %override wxLua_wxTreeCtrl_GetNextChild + // wxTreeItemId GetNextChild(const wxTreeItemId& item, long& cookie) const + static int LUACALL wxLua_wxTreeCtrl_GetNextChild(lua_State *L) + { + wxLuaState wxlState(L); + wxTreeItemId *returns; + + #if wxCHECK_VERSION(2, 5, 0) + wxTreeItemIdValue cookie = (wxTreeItemIdValue)(long)wxlState.GetNumberType(3); + #else + // long& cookie + long cookie = (long)lua_tonumber(L, 3); + #endif + // const wxTreeItemId& item + const wxTreeItemId *item = (wxTreeItemId *)wxlState.GetUserDataType(2, s_wxluatag_wxTreeItemId); + // get this + wxTreeCtrl *self = (wxTreeCtrl *)wxlState.GetUserDataType(1, s_wxluatag_wxTreeCtrl); + // call GetNextChild + // allocate a new object using the copy constructor + returns = new wxTreeItemId(self->GetNextChild(*item, cookie)); + // add the new object to the tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, returns); + // push the result datatype + wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); + #if wxCHECK_VERSION(2, 5, 0) + lua_pushnumber(L, (long)cookie); + #else + // push the cookie + lua_pushnumber(L, cookie); + #endif + // return the number of parameters + return 2; + } + // wxTreeItemId GetNextSibling(const wxTreeItemId& item) const static int LUACALL wxLua_wxTreeCtrl_GetNextSibling(lua_State *L) *************** *** 9801,9810 **** - #if ((wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl)) && (wxLUA_USE_wxTreeCtrl) - { LuaMethod, "GetFirstChild", wxLua_wxTreeCtrl_GetFirstChild, 2, 2, { &s_wxluatag_wxTreeItemId, &s_wxluatag_wxTreeItemIdValue, 0 } }, - { LuaMethod, "GetNextChild", wxLua_wxTreeCtrl_GetNextChild, 2, 2, { &s_wxluatag_wxTreeItemId, &s_wxluatag_wxTreeItemIdValue, 0 } }, - #endif - - #if ((wxLUA_USE_wxTreeCtrl) && (wxLUA_USE_wxValidator)) && (wxLUA_USE_wxPointSizeRect) { LuaConstructor, "wxTreeCtrl", wxLua_wxTreeCtrl_constructor, 7, 2, { &s_wxluatag_wxWindow, &s_wxluaarg_Number, &s_wxluatag_wxPoint, &s_wxluatag_wxSize, &s_wxluaarg_Number, &s_wxluatag_wxValidator, &s_wxluaarg_String, 0 } }, --- 9797,9800 ---- *************** *** 9864,9867 **** --- 9854,9858 ---- { LuaMethod, "GetChildrenCount", wxLua_wxTreeCtrl_GetChildrenCount, 2, 1, { &s_wxluatag_wxTreeItemId, &s_wxluaarg_Boolean, 0 } }, { LuaMethod, "GetCount", wxLua_wxTreeCtrl_GetCount, 0, 0, { 0 } }, + { LuaMethod, "GetFirstChild", wxLua_wxTreeCtrl_GetFirstChild, 2, 2, { &s_wxluatag_wxTreeItemId, &s_wxluaarg_LightUserData, 0 } }, { LuaMethod, "GetFirstVisibleItem", wxLua_wxTreeCtrl_GetFirstVisibleItem, 0, 0, { 0 } }, { LuaMethod, "GetIndent", wxLua_wxTreeCtrl_GetIndent, 0, 0, { 0 } }, *************** *** 9870,9873 **** --- 9861,9865 ---- { LuaMethod, "GetItemText", wxLua_wxTreeCtrl_GetItemText, 1, 1, { &s_wxluatag_wxTreeItemId, 0 } }, { LuaMethod, "GetLastChild", wxLua_wxTreeCtrl_GetLastChild, 1, 1, { &s_wxluatag_wxTreeItemId, 0 } }, + { LuaMethod, "GetNextChild", wxLua_wxTreeCtrl_GetNextChild, 2, 2, { &s_wxluatag_wxTreeItemId, &s_wxluaarg_LightUserData, 0 } }, { LuaMethod, "GetNextSibling", wxLua_wxTreeCtrl_GetNextSibling, 1, 1, { &s_wxluatag_wxTreeItemId, 0 } }, { LuaMethod, "GetNextVisible", wxLua_wxTreeCtrl_GetNextVisible, 1, 1, { &s_wxluatag_wxTreeItemId, 0 } }, *************** *** 10146,10177 **** - #if (wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl) - // ------------------------------------------------------------------------------------------------- - // Bind class wxTreeItemIdValue - // ------------------------------------------------------------------------------------------------- - - // Lua MetaTable Tag for Class - int s_wxluatag_wxTreeItemIdValue = -1; - - static int LUACALL wxLua_wxTreeItemIdValue_destructor(lua_State *) - { - return 0; - } - - - - - - // Map Lua Class Methods to C Binding Functions - static WXLUAMETHOD s_wxTreeItemIdValue_methods[] = { - { LuaDelete, "wxTreeItemIdValue", wxLua_wxTreeItemIdValue_destructor, 0, 0, {0} }, - }; - - // Extern accessor to class method map - WXLUAMETHOD* wxTreeItemIdValue_methods = s_wxTreeItemIdValue_methods; - int wxTreeItemIdValue_methodCount = sizeof(s_wxTreeItemIdValue_methods)/sizeof(s_wxTreeItemIdValue_methods[0]); - #endif - - #if wxLUA_USE_wxTreeCtrl // ------------------------------------------------------------------------------------------------- --- 10138,10141 ---- *************** *** 10348,10351 **** --- 10312,10613 ---- #if wxLUA_USE_wxTreeCtrl // ------------------------------------------------------------------------------------------------- + // Bind class wxArrayTreeItemIds + // ------------------------------------------------------------------------------------------------- + + // Lua MetaTable Tag for Class + int s_wxluatag_wxArrayTreeItemIds = -1; + + // %overload wxArrayTreeItemIds() + static int LUACALL wxLua_wxArrayTreeItemIds_constructor1(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayTreeItemIds *returns; + // call constructor + returns = new wxArrayTreeItemIds(); + // add to tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxArrayTreeItemIds *)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxArrayTreeItemIds, returns); + + return 1; + } + + // %overload %constructor wxArrayTreeItemIdsCopy(const wxArrayTreeItemIds& array) + static int LUACALL wxLua_wxArrayTreeItemIdsCopy_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayTreeItemIds *returns; + // const wxArrayTreeItemIds array + const wxArrayTreeItemIds * array = (const wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call constructor + returns = new wxArrayTreeItemIds(*array); + // add to tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxArrayTreeItemIds *)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxArrayTreeItemIds, returns); + + return 1; + } + + // void Add(const wxTreeItemId& id) + static int LUACALL wxLua_wxArrayTreeItemIds_Add(lua_State *L) + { + wxLuaState wxlState(L); + // const wxTreeItemId id + const wxTreeItemId * id = (const wxTreeItemId *)wxlState.GetUserDataType(2, s_wxluatag_wxTreeItemId); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Add + self->Add(*id); + + return 0; + } + + // void Alloc(size_t nCount) + static int LUACALL wxLua_wxArrayTreeItemIds_Alloc(lua_State *L) + { + wxLuaState wxlState(L); + // size_t nCount + size_t nCount = (size_t)wxlState.GetNumberType(2); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Alloc + self->Alloc(nCount); + + return 0; + } + + // void Clear() + static int LUACALL wxLua_wxArrayTreeItemIds_Clear(lua_State *L) + { + wxLuaState wxlState(L); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Clear + self->Clear(); + + return 0; + } + + // void Empty() + static int LUACALL wxLua_wxArrayTreeItemIds_Empty(lua_State *L) + { + wxLuaState wxlState(L); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Empty + self->Empty(); + + return 0; + } + + // int GetCount() const + static int LUACALL wxLua_wxArrayTreeItemIds_GetCount(lua_State *L) + { + wxLuaState wxlState(L); + int returns; + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call GetCount + returns = self->GetCount(); + // push the result number + lua_pushnumber(L, returns); + + return 1; + } + + // int Index(wxTreeItemIdValue treeItemIdValue, bool bFromEnd = false) + static int LUACALL wxLua_wxArrayTreeItemIds_Index(lua_State *L) + { + wxLuaState wxlState(L); + int returns; + // get number of arguments + int argCount = lua_gettop(L); + // bool bFromEnd = false + bool bFromEnd = (argCount >= 3 ? wxlState.GetBooleanType(3) : false); + // wxTreeItemIdValue treeItemIdValue + wxTreeItemIdValue treeItemIdValue = (wxTreeItemIdValue)wxlState.GetEnumerationType(2); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Index + returns = self->Index(treeItemIdValue, bFromEnd); + // push the result number + lua_pushnumber(L, returns); + + return 1; + } + + // bool IsEmpty() + static int LUACALL wxLua_wxArrayTreeItemIds_IsEmpty(lua_State *L) + { + wxLuaState wxlState(L); + bool returns; + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call IsEmpty + returns = self->IsEmpty(); + // push the result flag + lua_pushboolean(L, returns); + + return 1; + } + + // wxTreeItemId Item(size_t nIndex) const + static int LUACALL wxLua_wxArrayTreeItemIds_Item(lua_State *L) + { + wxLuaState wxlState(L); + wxTreeItemId *returns; + // size_t nIndex + size_t nIndex = (size_t)wxlState.GetNumberType(2); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Item + // allocate a new object using the copy constructor + returns = new wxTreeItemId(self->Item(nIndex)); + // add the new object to the tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxTreeItemId *)returns); + // push the result datatype + wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); + + return 1; + } + + // wxTreeItemId Last() + static int LUACALL wxLua_wxArrayTreeItemIds_Last(lua_State *L) + { + wxLuaState wxlState(L); + wxTreeItemId *returns; + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Last + // allocate a new object using the copy constructor + returns = new wxTreeItemId(self->Last()); + // add the new object to the tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxTreeItemId *)returns); + // push the result datatype + wxlState.PushUserDataType(s_wxluatag_wxTreeItemId, returns); + + return 1; + } + + // void Remove(wxTreeItemIdValue treeItemIdValue) + static int LUACALL wxLua_wxArrayTreeItemIds_Remove(lua_State *L) + { + wxLuaState wxlState(L); + // wxTreeItemIdValue treeItemIdValue + wxTreeItemIdValue treeItemIdValue = (wxTreeItemIdValue)wxlState.GetEnumerationType(2); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Remove + self->Remove(treeItemIdValue); + + return 0; + } + + // void RemoveAt(size_t nIndex, size_t count = 1) + static int LUACALL wxLua_wxArrayTreeItemIds_RemoveAt(lua_State *L) + { + wxLuaState wxlState(L); + // get number of arguments + int argCount = lua_gettop(L); + // size_t count = 1 + size_t count = (argCount >= 3 ? (size_t)wxlState.GetNumberType(3) : 1); + // size_t nIndex + size_t nIndex = (size_t)wxlState.GetNumberType(2); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call RemoveAt + self->RemoveAt(nIndex, count); + + return 0; + } + + // void Shrink() + static int LUACALL wxLua_wxArrayTreeItemIds_Shrink(lua_State *L) + { + wxLuaState wxlState(L); + // get this + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // call Shrink + self->Shrink(); + + return 0; + } + + static int LUACALL wxLua_wxArrayTreeItemIds_destructor(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + + // remove from tracked memory list + if (self != 0) + wxlState.RemoveTrackedMemory(self); + return 0; + } + + static int LUACALL wxLua_wxArrayTreeItemIds_Delete(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayTreeItemIds * self = (wxArrayTreeItemIds *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayTreeItemIds); + // remove from tracked memory list + if (self != 0) + if (wxlState.RemoveTrackedMemory(self)) + { // if removed, reset the tag so that gc() is not called on this object. + lua_pushnil(L); + lua_setmetatable(L, -2); + } + return 0; + } + + + + // Overloaded function bindings + + #if (wxLUA_USE_wxTreeCtrl) + // Overloaded functions for wxLua_wxArrayTreeItemIds_constructor + static int LUACALL wxLua_wxArrayTreeItemIds_constructor(lua_State *L) + { + // function overload table + static WXLUAMETHOD overloaded_methods[] = + { + { LuaConstructor, "wxArrayTreeItemIds", wxLua_wxArrayTreeItemIds_constructor1, 0, 0, { 0 } }, + { LuaConstructor, "wxArrayTreeItemIdsCopy", wxLua_wxArrayTreeItemIdsCopy_constructor, 1, 1, { &s_wxluatag_wxArrayTreeItemIds, 0 } }, + }; + static int overloaded_methodCount = sizeof(overloaded_methods)/sizeof(overloaded_methods[0]); + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(overloaded_methods, overloaded_methodCount); + } + #endif + + + + // Map Lua Class Methods to C Binding Functions + static WXLUAMETHOD s_wxArrayTreeItemIds_methods[] = { + { LuaConstructor, "wxArrayTreeItemIds", wxLua_wxArrayTreeItemIds_constructor, 0, 0, { 0 } }, + { LuaConstructor, "wxArrayTreeItemIdsCopy", wxLua_wxArrayTreeItemIdsCopy_constructor, 1, 1, { &s_wxluatag_wxArrayTreeItemIds, 0 } }, + { LuaMethod, "Add", wxLua_wxArrayTreeItemIds_Add, 1, 1, { &s_wxluatag_wxTreeItemId, 0 } }, + { LuaMethod, "Alloc", wxLua_wxArrayTreeItemIds_Alloc, 1, 1, { &s_wxluaarg_Number, 0 } }, + { LuaMethod, "Clear", wxLua_wxArrayTreeItemIds_Clear, 0, 0, { 0 } }, + { LuaMethod, "Empty", wxLua_wxArrayTreeItemIds_Empty, 0, 0, { 0 } }, + { LuaMethod, "GetCount", wxLua_wxArrayTreeItemIds_GetCount, 0, 0, { 0 } }, + { LuaMethod, "Index", wxLua_wxArrayTreeItemIds_Index, 2, 1, { &s_wxluaarg_Enumeration, &s_wxluaarg_Boolean, 0 } }, + { LuaMethod, "IsEmpty", wxLua_wxArrayTreeItemIds_IsEmpty, 0, 0, { 0 } }, + { LuaMethod, "Item", wxLua_wxArrayTreeItemIds_Item, 1, 1, { &s_wxluaarg_Number, 0 } }, + { LuaMethod, "Last", wxLua_wxArrayTreeItemIds_Last, 0, 0, { 0 } }, + { LuaMethod, "Remove", wxLua_wxArrayTreeItemIds_Remove, 1, 1, { &s_wxluaarg_Enumeration, 0 } }, + { LuaMethod, "RemoveAt", wxLua_wxArrayTreeItemIds_RemoveAt, 2, 1, { &s_wxluaarg_Number, &s_wxluaarg_Number, 0 } }, + { LuaMethod, "Shrink", wxLua_wxArrayTreeItemIds_Shrink, 0, 0, { 0 } }, + { LuaDelete, "wxArrayTreeItemIds", wxLua_wxArrayTreeItemIds_destructor, 0, 0, {0} }, + { LuaMethod, "Delete", wxLua_wxArrayTreeItemIds_Delete, 0, 0, {0} }, + }; + + // Extern accessor to class method map + WXLUAMETHOD* wxArrayTreeItemIds_methods = s_wxArrayTreeItemIds_methods; + int wxArrayTreeItemIds_methodCount = sizeof(s_wxArrayTreeItemIds_methods)/sizeof(s_wxArrayTreeItemIds_methods[0]); + #endif + + + #if wxLUA_USE_wxTreeCtrl + // ------------------------------------------------------------------------------------------------- // Bind class wxTreeItemData // ------------------------------------------------------------------------------------------------- |
From: John L. <jr...@us...> - 2006-05-26 20:22:21
|
Update of /cvsroot/wxlua/wxLua/bindings/wxstc In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10865/wxLua/bindings/wxstc Modified Files: wxstc_datatypes.lua Log Message: add wxArrayTreeItemIds and hack for wxTreeItemIdValue Index: wxstc_datatypes.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxstc/wxstc_datatypes.lua,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** wxstc_datatypes.lua 25 May 2006 22:50:04 -0000 1.29 --- wxstc_datatypes.lua 26 May 2006 20:22:08 -0000 1.30 *************** *** 223,226 **** --- 223,232 ---- Name = "wxArrayString_FromLuaTable", }, + wxArrayTreeItemIds = { + Condition = "wxLUA_USE_wxTreeCtrl", + DefType = "class", + Intrinsic = false, + Name = "wxArrayTreeItemIds", + }, wxArtProvider = { BaseClass = "wxObject", *************** *** 2927,2933 **** }, wxTreeItemIdValue = { ! Condition = "(wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl)", ! DefType = "class", ! Intrinsic = false, Name = "wxTreeItemIdValue", }, --- 2933,2939 ---- }, wxTreeItemIdValue = { ! Condition = "wxLUA_USE_wxTreeCtrl", ! DefType = "enum", ! Intrinsic = true, Name = "wxTreeItemIdValue", }, |
From: John L. <jr...@us...> - 2006-05-26 20:22:20
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/include In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv10865/wxLua/modules/wxbind/include Modified Files: wxbind.h Log Message: add wxArrayTreeItemIds and hack for wxTreeItemIdValue Index: wxbind.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/include/wxbind.h,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** wxbind.h 25 May 2006 22:50:05 -0000 1.31 --- wxbind.h 26 May 2006 20:22:14 -0000 1.32 *************** *** 747,755 **** - #if (wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl) - extern WXDLLIMPEXP_DATA_WXBIND(int) s_wxluatag_wxTreeItemIdValue; - #endif - - #if (wxLUA_USE_wxBitmapButton) && (wxLUA_USE_wxButton) extern WXDLLIMPEXP_DATA_WXBIND(int) s_wxluatag_wxBitmapButton; --- 747,750 ---- *************** *** 1585,1588 **** --- 1580,1584 ---- #if wxLUA_USE_wxTreeCtrl + extern WXDLLIMPEXP_DATA_WXBIND(int) s_wxluatag_wxArrayTreeItemIds; extern WXDLLIMPEXP_DATA_WXBIND(int) s_wxluatag_wxLuaTreeItemData; extern WXDLLIMPEXP_DATA_WXBIND(int) s_wxluatag_wxTreeCtrl; *************** *** 1701,1710 **** - #if (wxCHECK_VERSION(2,5,0)) && (wxLUA_USE_wxTreeCtrl) - extern WXDLLIMPEXP_WXBIND WXLUAMETHOD* wxTreeItemIdValue_methods; - extern WXDLLIMPEXP_DATA_WXBIND(int) wxTreeItemIdValue_methodCount; - #endif - - #if (wxLUA_USE_wxBitmapButton) && (wxLUA_USE_wxButton) extern WXDLLIMPEXP_WXBIND WXLUAMETHOD* wxBitmapButton_methods; --- 1697,1700 ---- *************** *** 2856,2859 **** --- 2846,2851 ---- #if wxLUA_USE_wxTreeCtrl + extern WXDLLIMPEXP_WXBIND WXLUAMETHOD* wxArrayTreeItemIds_methods; + extern WXDLLIMPEXP_DATA_WXBIND(int) wxArrayTreeItemIds_methodCount; extern WXDLLIMPEXP_WXBIND WXLUAMETHOD* wxLuaTreeItemData_methods; extern WXDLLIMPEXP_DATA_WXBIND(int) wxLuaTreeItemData_methodCount; *************** *** 3069,3072 **** --- 3061,3065 ---- #if wxLUA_USE_wxTreeCtrl + wxLUA_DECLARE_ENCAPSULATION(WXDLLIMPEXP_WXBIND, wxArrayTreeItemIds) wxLUA_DECLARE_ENCAPSULATION(WXDLLIMPEXP_WXBIND, wxTreeItemId) #endif |
From: John L. <jr...@us...> - 2006-05-26 03:51:32
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv24769/wxLua/modules/wxbind/src Modified Files: appframe.cpp clipdrag.cpp controls.cpp data.cpp Log Message: add wxArrayInt/String constructors and ToLuaTable() func add more default constructors Index: data.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/data.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** data.cpp 24 May 2006 04:50:01 -0000 1.22 --- data.cpp 26 May 2006 03:19:51 -0000 1.23 *************** *** 1651,1654 **** --- 1651,1713 ---- int s_wxluatag_wxArrayInt = -1; + // %overload wxArrayInt() + static int LUACALL wxLua_wxArrayInt_constructor1(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayInt *returns; + // call constructor + returns = new wxArrayInt(); + // add to tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxArrayInt *)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxArrayInt, returns); + + return 1; + } + + // %overload %constructor wxArrayIntCopy(const wxArrayInt& array) + static int LUACALL wxLua_wxArrayIntCopy_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayInt *returns; + // const wxArrayInt array + const wxArrayInt * array = (const wxArrayInt *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayInt); + // call constructor + returns = new wxArrayInt(*array); + // add to tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxArrayInt *)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxArrayInt, returns); + + return 1; + } + + // %overload %constructor wxArrayIntFromTable(const wxArrayInt_FromLuaTable& array) + static int LUACALL wxLua_wxArrayIntFromTable_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayInt *returns; + // const wxArrayInt_FromLuaTable array + wxArrayInt array = wxArrayInt(); wxlState.GetwxArrayInt(1, array); + // call constructor + returns = new wxArrayInt(array); + // add to tracked memory list + wxLua_AddToTrackedMemoryList(wxlState, (wxArrayInt *)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxArrayInt, returns); + + return 1; + } + + // %override wxLua_wxArrayInt_ToLuaTable + // int ToLuaTable const + static int LUACALL wxLua_wxArrayInt_ToLuaTable(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayInt * self = (wxArrayInt *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayInt); + wxlState.PushwxArrayIntTable(*self); + return 1; + } + // void Add( int num ) static int LUACALL wxLua_wxArrayInt_Add(lua_State *L) *************** *** 1858,1865 **** --- 1917,1947 ---- + // Overloaded function bindings + + #if (wxLUA_USE_wxArrayInt) + // Overloaded functions for wxLua_wxArrayInt_constructor + static int LUACALL wxLua_wxArrayInt_constructor(lua_State *L) + { + // function overload table + static WXLUAMETHOD overloaded_methods[] = + { + { LuaConstructor, "wxArrayInt", wxLua_wxArrayInt_constructor1, 0, 0, { 0 } }, + { LuaConstructor, "wxArrayIntCopy", wxLua_wxArrayIntCopy_constructor, 1, 1, { &s_wxluatag_wxArrayInt, 0 } }, + { LuaConstructor, "wxArrayIntFromTable", wxLua_wxArrayIntFromTable_constructor, 1, 1, { &s_wxluaarg_LuaTable, 0 } }, + }; + static int overloaded_methodCount = sizeof(overloaded_methods)/sizeof(overloaded_methods[0]); + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(overloaded_methods, overloaded_methodCount); + } + #endif + // Map Lua Class Methods to C Binding Functions static WXLUAMETHOD s_wxArrayInt_methods[] = { + { LuaConstructor, "wxArrayInt", wxLua_wxArrayInt_constructor, 0, 0, { 0 } }, + { LuaConstructor, "wxArrayIntCopy", wxLua_wxArrayIntCopy_constructor, 1, 1, { &s_wxluatag_wxArrayInt, 0 } }, + { LuaConstructor, "wxArrayIntFromTable", wxLua_wxArrayIntFromTable_constructor, 1, 1, { &s_wxluaarg_LuaTable, 0 } }, + { LuaMethod, "ToLuaTable", wxLua_wxArrayInt_ToLuaTable, 0, 0, { 0 } }, { LuaMethod, "Add", wxLua_wxArrayInt_Add, 1, 1, { &s_wxluaarg_Number, 0 } }, { LuaMethod, "Alloc", wxLua_wxArrayInt_Alloc, 1, 1, { &s_wxluaarg_Number, 0 } }, *************** *** 1893,1898 **** int s_wxluatag_wxArrayString = -1; ! // wxArrayString() ! static int LUACALL wxLua_wxArrayString_constructor(lua_State *L) { wxLuaState wxlState(L); --- 1975,1980 ---- int s_wxluatag_wxArrayString = -1; ! // %overload wxArrayString() ! static int LUACALL wxLua_wxArrayString_constructor1(lua_State *L) { wxLuaState wxlState(L); *************** *** 1908,1912 **** } ! // %constructor wxArrayStringCopy(const wxArrayString& array) static int LUACALL wxLua_wxArrayStringCopy_constructor(lua_State *L) { --- 1990,1994 ---- } ! // %overload %constructor wxArrayStringCopy(const wxArrayString& array) static int LUACALL wxLua_wxArrayStringCopy_constructor(lua_State *L) { *************** *** 1925,1929 **** } ! // %constructor wxArrayStringFromTable(const wxArrayString_FromLuaTable& array) static int LUACALL wxLua_wxArrayStringFromTable_constructor(lua_State *L) { --- 2007,2011 ---- } ! // %overload %constructor wxArrayStringFromTable(const wxArrayString_FromLuaTable& array) static int LUACALL wxLua_wxArrayStringFromTable_constructor(lua_State *L) { *************** *** 1942,1945 **** --- 2024,2037 ---- } + // %override wxLua_wxArrayString_ToLuaTable + // int ToLuaTable const + static int LUACALL wxLua_wxArrayString_ToLuaTable(lua_State *L) + { + wxLuaState wxlState(L); + wxArrayString * self = (wxArrayString *)wxlState.GetUserDataType(1, s_wxluatag_wxArrayString); + wxlState.PushwxArrayStringTable(*self); + return 1; + } + // size_t Add(const wxString& str, size_t copies = 1) static int LUACALL wxLua_wxArrayString_Add(lua_State *L) *************** *** 2193,2196 **** --- 2285,2307 ---- + // Overloaded function bindings + + #if (wxLUA_USE_wxArrayString) + // Overloaded functions for wxLua_wxArrayString_constructor + static int LUACALL wxLua_wxArrayString_constructor(lua_State *L) + { + // function overload table + static WXLUAMETHOD overloaded_methods[] = + { + { LuaConstructor, "wxArrayString", wxLua_wxArrayString_constructor1, 0, 0, { 0 } }, + { LuaConstructor, "wxArrayStringCopy", wxLua_wxArrayStringCopy_constructor, 1, 1, { &s_wxluatag_wxArrayString, 0 } }, + { LuaConstructor, "wxArrayStringFromTable", wxLua_wxArrayStringFromTable_constructor, 1, 1, { &s_wxluaarg_LuaTable, 0 } }, + }; + static int overloaded_methodCount = sizeof(overloaded_methods)/sizeof(overloaded_methods[0]); + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(overloaded_methods, overloaded_methodCount); + } + #endif + *************** *** 2200,2203 **** --- 2311,2315 ---- { LuaConstructor, "wxArrayStringCopy", wxLua_wxArrayStringCopy_constructor, 1, 1, { &s_wxluatag_wxArrayString, 0 } }, { LuaConstructor, "wxArrayStringFromTable", wxLua_wxArrayStringFromTable_constructor, 1, 1, { &s_wxluaarg_LuaTable, 0 } }, + { LuaMethod, "ToLuaTable", wxLua_wxArrayString_ToLuaTable, 0, 0, { 0 } }, { LuaMethod, "Add", wxLua_wxArrayString_Add, 2, 1, { &s_wxluaarg_String, &s_wxluaarg_Number, 0 } }, { LuaMethod, "Alloc", wxLua_wxArrayString_Alloc, 1, 1, { &s_wxluaarg_Number, 0 } }, Index: controls.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/controls.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** controls.cpp 25 May 2006 22:50:05 -0000 1.27 --- controls.cpp 26 May 2006 03:19:51 -0000 1.28 *************** *** 129,132 **** --- 129,148 ---- #endif + // %constructor wxButtonDefault() + static int LUACALL wxLua_wxButtonDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxButton *returns; + // call constructor + returns = new wxButton(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxButton, returns); + + return 1; + } + // void SetDefault() static int LUACALL wxLua_wxButton_SetDefault(lua_State *L) *************** *** 164,167 **** --- 180,184 ---- #endif + { LuaConstructor, "wxButtonDefault", wxLua_wxButtonDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "SetDefault", wxLua_wxButton_SetDefault, 0, 0, { 0 } }, { LuaDelete, "wxButton", wxLua_wxButton_destructor, 0, 0, {0} }, *************** *** 385,388 **** --- 402,421 ---- #endif + // %constructor wxBitmapButtonDefault() + static int LUACALL wxLua_wxBitmapButtonDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxBitmapButton *returns; + // call constructor + returns = new wxBitmapButton(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxBitmapButton, returns); + + return 1; + } + static int LUACALL wxLua_wxBitmapButton_destructor(lua_State *) { *************** *** 422,425 **** --- 455,459 ---- #endif + { LuaConstructor, "wxBitmapButtonDefault", wxLua_wxBitmapButtonDefault_constructor, 0, 0, { 0 } }, { LuaDelete, "wxBitmapButton", wxLua_wxBitmapButton_destructor, 0, 0, {0} }, }; *************** *** 510,513 **** --- 544,563 ---- #endif + // %constructor wxToggleButtonDefault() + static int LUACALL wxLua_wxToggleButtonDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxToggleButton *returns; + // call constructor + returns = new wxToggleButton(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxToggleButton, returns); + + return 1; + } + // void SetValue(bool state) static int LUACALL wxLua_wxToggleButton_SetValue(lua_State *L) *************** *** 556,559 **** --- 606,610 ---- #endif + { LuaConstructor, "wxToggleButtonDefault", wxLua_wxToggleButtonDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "SetValue", wxLua_wxToggleButton_SetValue, 1, 1, { &s_wxluaarg_Boolean, 0 } }, { LuaMethod, "GetValue", wxLua_wxToggleButton_GetValue, 0, 0, { 0 } }, *************** *** 646,649 **** --- 697,716 ---- #endif + // %constructor wxCheckBoxDefault() + static int LUACALL wxLua_wxCheckBoxDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxCheckBox *returns; + // call constructor + returns = new wxCheckBox(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxCheckBox, returns); + + return 1; + } + // bool GetValue() const static int LUACALL wxLua_wxCheckBox_GetValue(lua_State *L) *************** *** 766,769 **** --- 833,837 ---- #endif + { LuaConstructor, "wxCheckBoxDefault", wxLua_wxCheckBoxDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetValue", wxLua_wxCheckBox_GetValue, 0, 0, { 0 } }, { LuaMethod, "Get3StateValue", wxLua_wxCheckBox_Get3StateValue, 0, 0, { 0 } }, *************** *** 1267,1270 **** --- 1335,1354 ---- #endif + // %constructor wxChoiceDefault() + static int LUACALL wxLua_wxChoiceDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxChoice *returns; + // call constructor + returns = new wxChoice(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxChoice, returns); + + return 1; + } + // int GetCurrentSelection() const static int LUACALL wxLua_wxChoice_GetCurrentSelection(lua_State *L) *************** *** 1299,1302 **** --- 1383,1387 ---- #endif + { LuaConstructor, "wxChoiceDefault", wxLua_wxChoiceDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetCurrentSelection", wxLua_wxChoice_GetCurrentSelection, 0, 0, { 0 } }, { LuaDelete, "wxChoice", wxLua_wxChoice_destructor, 0, 0, {0} }, *************** *** 1392,1395 **** --- 1477,1496 ---- #endif + // %constructor wxComboBoxDefault() + static int LUACALL wxLua_wxComboBoxDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxComboBox *returns; + // call constructor + returns = new wxComboBox(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxComboBox, returns); + + return 1; + } + // bool CanCopy() const static int LUACALL wxLua_wxComboBox_CanCopy(lua_State *L) *************** *** 1679,1682 **** --- 1780,1784 ---- #endif + { LuaConstructor, "wxComboBoxDefault", wxLua_wxComboBoxDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "CanCopy", wxLua_wxComboBox_CanCopy, 0, 0, { 0 } }, { LuaMethod, "CanCut", wxLua_wxComboBox_CanCut, 0, 0, { 0 } }, *************** *** 1790,1793 **** --- 1892,1911 ---- #endif + // %constructor wxGaugeDefault() + static int LUACALL wxLua_wxGaugeDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxGauge *returns; + // call constructor + returns = new wxGauge(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxGauge, returns); + + return 1; + } + // int GetBezelFace() const static int LUACALL wxLua_wxGauge_GetBezelFace(lua_State *L) *************** *** 1938,1941 **** --- 2056,2060 ---- #endif + { LuaConstructor, "wxGaugeDefault", wxLua_wxGaugeDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetBezelFace", wxLua_wxGauge_GetBezelFace, 0, 0, { 0 } }, { LuaMethod, "GetRange", wxLua_wxGauge_GetRange, 0, 0, { 0 } }, *************** *** 2043,2046 **** --- 2162,2181 ---- #endif + // %constructor wxListBoxDefault() + static int LUACALL wxLua_wxListBoxDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxListBox *returns; + // call constructor + returns = new wxListBox(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxListBox, returns); + + return 1; + } + // void Deselect(int n) static int LUACALL wxLua_wxListBox_Deselect(lua_State *L) *************** *** 2191,2194 **** --- 2326,2330 ---- #endif + { LuaConstructor, "wxListBoxDefault", wxLua_wxListBoxDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "Deselect", wxLua_wxListBox_Deselect, 1, 1, { &s_wxluaarg_Number, 0 } }, { LuaMethod, "GetSelections", wxLua_wxListBox_GetSelections, 0, 0, { 0 } }, *************** *** 2287,2290 **** --- 2423,2442 ---- #endif + // %constructor wxCheckListBoxDefault() + static int LUACALL wxLua_wxCheckListBoxDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxCheckListBox *returns; + // call constructor + returns = new wxCheckListBox(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxCheckListBox, returns); + + return 1; + } + // void Check(int item, bool check = true) static int LUACALL wxLua_wxCheckListBox_Check(lua_State *L) *************** *** 2339,2342 **** --- 2491,2495 ---- #endif + { LuaConstructor, "wxCheckListBoxDefault", wxLua_wxCheckListBoxDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "Check", wxLua_wxCheckListBox_Check, 2, 1, { &s_wxluaarg_Number, &s_wxluaarg_Boolean, 0 } }, { LuaMethod, "IsChecked", wxLua_wxCheckListBox_IsChecked, 1, 1, { &s_wxluaarg_Number, 0 } }, *************** *** 5139,5142 **** --- 5292,5311 ---- #endif + // %constructor wxRadioBoxDefault() + static int LUACALL wxLua_wxRadioBoxDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxRadioBox *returns; + // call constructor + returns = new wxRadioBox(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxRadioBox, returns); + + return 1; + } + // %overload void Enable(bool enable) static int LUACALL wxLua_wxRadioBox_Enable1(lua_State *L) *************** *** 5384,5387 **** --- 5553,5557 ---- #endif + { LuaConstructor, "wxRadioBoxDefault", wxLua_wxRadioBoxDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "Enable", wxLua_wxRadioBox_Enable, 1, 1, { &s_wxluaarg_Boolean, 0 } }, { LuaMethod, "EnableItem", wxLua_wxRadioBox_EnableItem, 2, 2, { &s_wxluaarg_Number, &s_wxluaarg_Boolean, 0 } }, *************** *** 5489,5492 **** --- 5659,5678 ---- #endif + // %constructor wxRadioButtonDefault() + static int LUACALL wxLua_wxRadioButtonDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxRadioButton *returns; + // call constructor + returns = new wxRadioButton(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxRadioButton, returns); + + return 1; + } + // bool GetValue() const static int LUACALL wxLua_wxRadioButton_GetValue(lua_State *L) *************** *** 5535,5538 **** --- 5721,5725 ---- #endif + { LuaConstructor, "wxRadioButtonDefault", wxLua_wxRadioButtonDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetValue", wxLua_wxRadioButton_GetValue, 0, 0, { 0 } }, { LuaMethod, "SetValue", wxLua_wxRadioButton_SetValue, 1, 1, { &s_wxluaarg_Boolean, 0 } }, *************** *** 5623,5626 **** --- 5810,5829 ---- #endif + // %constructor wxScrollBarDefault() + static int LUACALL wxLua_wxScrollBarDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxScrollBar *returns; + // call constructor + returns = new wxScrollBar(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxScrollBar, returns); + + return 1; + } + // int GetRange() const static int LUACALL wxLua_wxScrollBar_GetRange(lua_State *L) *************** *** 5738,5741 **** --- 5941,5945 ---- #endif + { LuaConstructor, "wxScrollBarDefault", wxLua_wxScrollBarDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetRange", wxLua_wxScrollBar_GetRange, 0, 0, { 0 } }, { LuaMethod, "GetPageSize", wxLua_wxScrollBar_GetPageSize, 0, 0, { 0 } }, *************** *** 5844,5847 **** --- 6048,6067 ---- #endif + // %constructor wxSliderDefault() + static int LUACALL wxLua_wxSliderDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxSlider *returns; + // call constructor + returns = new wxSlider(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxSlider, returns); + + return 1; + } + // void ClearSel() static int LUACALL wxLua_wxSlider_ClearSel(lua_State *L) *************** *** 6138,6141 **** --- 6358,6362 ---- #endif + { LuaConstructor, "wxSliderDefault", wxLua_wxSliderDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "ClearSel", wxLua_wxSlider_ClearSel, 0, 0, { 0 } }, { LuaMethod, "ClearTicks", wxLua_wxSlider_ClearTicks, 0, 0, { 0 } }, *************** *** 6249,6252 **** --- 6470,6489 ---- #endif + // %constructor wxSpinButtonDefault() + static int LUACALL wxLua_wxSpinButtonDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxSpinButton *returns; + // call constructor + returns = new wxSpinButton(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxSpinButton, returns); + + return 1; + } + // int GetMax() const static int LUACALL wxLua_wxSpinButton_GetMax(lua_State *L) *************** *** 6341,6344 **** --- 6578,6582 ---- #endif + { LuaConstructor, "wxSpinButtonDefault", wxLua_wxSpinButtonDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetMax", wxLua_wxSpinButton_GetMax, 0, 0, { 0 } }, { LuaMethod, "GetMin", wxLua_wxSpinButton_GetMin, 0, 0, { 0 } }, *************** *** 6550,6553 **** --- 6788,6807 ---- #endif + // %constructor wxSpinCtrlDefault() + static int LUACALL wxLua_wxSpinCtrlDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxSpinCtrl *returns; + // call constructor + returns = new wxSpinCtrl(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxSpinCtrl, returns); + + return 1; + } + // int GetMax() const static int LUACALL wxLua_wxSpinCtrl_GetMax(lua_State *L) *************** *** 6690,6693 **** --- 6944,6948 ---- #endif + { LuaConstructor, "wxSpinCtrlDefault", wxLua_wxSpinCtrlDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "GetMax", wxLua_wxSpinCtrl_GetMax, 0, 0, { 0 } }, { LuaMethod, "GetMin", wxLua_wxSpinCtrl_GetMin, 0, 0, { 0 } }, *************** *** 6838,6841 **** --- 7093,7112 ---- #endif + // %constructor wxTextCtrlDefault() + static int LUACALL wxLua_wxTextCtrlDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxTextCtrl *returns; + // call constructor + returns = new wxTextCtrl(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxTextCtrl, returns); + + return 1; + } + // void AppendText(const wxString& text) static int LUACALL wxLua_wxTextCtrl_AppendText(lua_State *L) *************** *** 7561,7564 **** --- 7832,7836 ---- #endif + { LuaConstructor, "wxTextCtrlDefault", wxLua_wxTextCtrlDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "AppendText", wxLua_wxTextCtrl_AppendText, 1, 1, { &s_wxluaarg_String, 0 } }, { LuaMethod, "CanCopy", wxLua_wxTextCtrl_CanCopy, 0, 0, { 0 } }, *************** *** 8605,8608 **** --- 8877,8896 ---- #endif + // %constructor wxTreeCtrlDefault() + static int LUACALL wxLua_wxTreeCtrlDefault_constructor(lua_State *L) + { + wxLuaState wxlState(L); + wxTreeCtrl *returns; + // call constructor + returns = new wxTreeCtrl(); + // add to tracked window list + if (returns && returns->IsKindOf(CLASSINFO(wxWindow))) + wxlState.AddToTrackedWindowList((wxWindow*)returns); + // push the constructed class pointer + wxlState.PushUserDataType(s_wxluatag_wxTreeCtrl, returns); + + return 1; + } + // wxTreeItemId AddRoot(const wxString& text, int image = -1, int selImage = -1, wxTreeItemData* data = NULL) static int LUACALL wxLua_wxTreeCtrl_AddRoot(lua_State *L) *************** *** 9563,9566 **** --- 9851,9855 ---- #endif + { LuaConstructor, "wxTreeCtrlDefault", wxLua_wxTreeCtrlDefault_constructor, 0, 0, { 0 } }, { LuaMethod, "AddRoot", wxLua_wxTreeCtrl_AddRoot, 4, 1, { &s_wxluaarg_String, &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluatag_wxTreeItemData, 0 } }, { LuaMethod, "AppendItem", wxLua_wxTreeCtrl_AppendItem, 5, 2, { &s_wxluatag_wxTreeItemId, &s_wxluaarg_String, &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluatag_wxTreeItemData, 0 } }, Index: clipdrag.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/clipdrag.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** clipdrag.cpp 18 May 2006 05:47:39 -0000 1.19 --- clipdrag.cpp 26 May 2006 03:19:51 -0000 1.20 *************** *** 237,242 **** int s_wxluatag_wxDataFormat = -1; ! // %override wxDataFormat(wxDataFormatId format = wxDF_INVALID) ! static int LUACALL wxLua_wxDataFormat_constructor(lua_State *L) { wxLuaState wxlState(L); --- 237,242 ---- int s_wxluatag_wxDataFormat = -1; ! // %overload wxDataFormat(wxDataFormatId format = wxDF_INVALID) ! static int LUACALL wxLua_wxDataFormat_constructor1(lua_State *L) { wxLuaState wxlState(L); *************** *** 256,260 **** } ! // %override %constructor wxDataFormatUser(const wxString &format) static int LUACALL wxLua_wxDataFormatUser_constructor(lua_State *L) { --- 256,260 ---- } ! // %overload %constructor wxDataFormatUser(const wxString &format) static int LUACALL wxLua_wxDataFormatUser_constructor(lua_State *L) { *************** *** 375,378 **** --- 375,396 ---- + // Overloaded function bindings + + #if (wxLUA_USE_wxDataObject) + // Overloaded functions for wxLua_wxDataFormat_constructor + static int LUACALL wxLua_wxDataFormat_constructor(lua_State *L) + { + // function overload table + static WXLUAMETHOD overloaded_methods[] = + { + { LuaConstructor, "wxDataFormat", wxLua_wxDataFormat_constructor1, 1, 0, { &s_wxluaarg_Enumeration, 0 } }, + { LuaConstructor, "wxDataFormatUser", wxLua_wxDataFormatUser_constructor, 1, 1, { &s_wxluaarg_String, 0 } }, + }; + static int overloaded_methodCount = sizeof(overloaded_methods)/sizeof(overloaded_methods[0]); + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(overloaded_methods, overloaded_methodCount); + } + #endif + Index: appframe.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/appframe.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** appframe.cpp 25 May 2006 22:50:05 -0000 1.18 --- appframe.cpp 26 May 2006 03:19:51 -0000 1.19 *************** *** 1835,1840 **** int s_wxluatag_wxAcceleratorEntry = -1; ! // wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0) ! static int LUACALL wxLua_wxAcceleratorEntry_constructor(lua_State *L) { wxLuaState wxlState(L); --- 1835,1840 ---- int s_wxluatag_wxAcceleratorEntry = -1; ! // %overload wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0) ! static int LUACALL wxLua_wxAcceleratorEntry_constructor1(lua_State *L) { wxLuaState wxlState(L); *************** *** 1858,1862 **** } ! // %constructor wxAcceleratorEntryCopy(const wxAcceleratorEntry& entry) static int LUACALL wxLua_wxAcceleratorEntryCopy_constructor(lua_State *L) { --- 1858,1862 ---- } ! // %overload %constructor wxAcceleratorEntryCopy(const wxAcceleratorEntry& entry) static int LUACALL wxLua_wxAcceleratorEntryCopy_constructor(lua_State *L) { *************** *** 1965,1968 **** --- 1965,1986 ---- + // Overloaded function bindings + + #if (wxLUA_USE_wxAcceleratorTable) + // Overloaded functions for wxLua_wxAcceleratorEntry_constructor + static int LUACALL wxLua_wxAcceleratorEntry_constructor(lua_State *L) + { + // function overload table + static WXLUAMETHOD overloaded_methods[] = + { + { LuaConstructor, "wxAcceleratorEntry", wxLua_wxAcceleratorEntry_constructor1, 3, 0, { &s_wxluaarg_Number, &s_wxluaarg_Number, &s_wxluaarg_Number, 0 } }, + { LuaConstructor, "wxAcceleratorEntryCopy", wxLua_wxAcceleratorEntryCopy_constructor, 1, 1, { &s_wxluatag_wxAcceleratorEntry, 0 } }, + }; + static int overloaded_methodCount = sizeof(overloaded_methods)/sizeof(overloaded_methods[0]); + wxLuaState wxlState(L); + return wxlState.CallOverloadedFunction(overloaded_methods, overloaded_methodCount); + } + #endif + |