@@ -326,8 +326,6 @@ static int gen_inputbox (lua_State *L, T & msg)
326
326
CString strOKbuttonLabel;
327
327
CString strCancelbuttonLabel;
328
328
329
-
330
-
331
329
// if arg6 present, and a table, grab extra stuff
332
330
if (lua_istable (L, nExtraStuffArg))
333
331
{
@@ -348,10 +346,15 @@ static int gen_inputbox (lua_State *L, T & msg)
348
346
if (!lua_isnil (L, -1 ))
349
347
{
350
348
if (!lua_isfunction (L, -1 ))
351
- luaL_error (L, " inputbox argument 6 value for 'validate' must be a function" );
349
+ luaL_error (L, " inputbox argument # 6 value for 'validate' must be a function" );
352
350
353
351
lua_pushvalue (L, -1 ); // function is now on top of stack
354
352
msg.m_L = L; // non-NULL indicates we have function there
353
+
354
+ // we can't leave the function on the stack, that gets cleared from time to time
355
+ // while the dialog box is running - so we store it in the registry and get the
356
+ // unique index back
357
+ msg.m_iValidationIndex = luaL_ref (L, LUA_REGISTRYINDEX);
355
358
} // validate function there
356
359
357
360
} // table of extra stuff there
@@ -382,11 +385,16 @@ static int gen_inputbox (lua_State *L, T & msg)
382
385
msg.m_strOKbuttonLabel = strOKbuttonLabel ;
383
386
msg.m_strCancelbuttonLabel = strCancelbuttonLabel;
384
387
388
+ lua_settop (L, 0 );
389
+
385
390
if (msg.DoModal () != IDOK)
386
391
lua_pushnil (L);
387
392
else
388
393
lua_pushstring (L, msg.m_strReply );
389
394
395
+ // free up registry entry (is OK with LUA_NOREF)
396
+ luaL_unref (L, LUA_REGISTRYINDEX, msg.m_iValidationIndex );
397
+
390
398
return 1 ;
391
399
} // end of gen_inputbox
392
400
@@ -1754,11 +1762,15 @@ CFunctionListDlg dlg;
1754
1762
if (!lua_isnil (L, 5 ))
1755
1763
{
1756
1764
luaL_checktype (L, 5 , LUA_TFUNCTION);
1757
- lua_remove (L, 1 ); // get rid of bottom 4 items
1758
- lua_remove (L, 1 );
1759
- lua_remove (L, 1 );
1760
- lua_remove (L, 1 );
1761
- dlg.m_L = L; // function is now at stack item 1
1765
+ lua_pushvalue (L, 5 ); // function is now on top of stack
1766
+
1767
+ dlg.m_L = L;
1768
+
1769
+ // we can't leave the function on the stack, that gets cleared from time to time
1770
+ // while the dialog box is running - so we store it in the registry and get the
1771
+ // unique index back
1772
+ dlg.m_iFilterIndex = luaL_ref (L, LUA_REGISTRYINDEX);
1773
+
1762
1774
}
1763
1775
}
1764
1776
@@ -1777,6 +1789,9 @@ CFunctionListDlg dlg;
1777
1789
}
1778
1790
}
1779
1791
1792
+ // free up registry entry (is OK with LUA_NOREF)
1793
+ luaL_unref (L, LUA_REGISTRYINDEX, dlg.m_iFilterIndex );
1794
+
1780
1795
return 1 ; // 1 result
1781
1796
1782
1797
} // end of filterpicker
0 commit comments