Hi,
I got a strange behavior when creating a dialog from a coroutine, and 
resuming the coroutine when a dialog button is clicked. It seems the 
function called by the button click event is executed as if it was 
called by the coroutine, while, unless I'm missing something obvious, it 
should not. I've isolated the problem in a small application :

-- I overwrite print and assert functions to get messages in the console 
window
local print = print -- don't want wxLua print function
local assert = function( cond, msg, ... )
    if not cond then
        print( "Assertion failed: "..msg )
        print( debug.traceback() )
    end
    return cond, msg, ...
end

require( "wx" )

function callback()
    print( "Button clicked" )
    assert( coroutine.resume( co ) )
end

function createDialog()
    dialog = wx.wxDialog( wx.NULL, wx.wxID_ANY, "Test dialog", 
wx.wxDefaultPosition, wx.wxDefaultSize )
    panel = wx.wxPanel( dialog, wx.wxID_ANY )
    sizer = wx.wxBoxSizer( wx.wxHORIZONTAL )

    button = wx.wxButton( panel, wx.wxID_ANY, "Test button" )
    dialog:Connect( button:GetId(), wx.wxEVT_COMMAND_BUTTON_CLICKED, 
callback )

    sizer:Add( button )

    panel:SetSizer( sizer )
    sizer:SetSizeHints( dialog )
    dialog:Show( true )
end

co = coroutine.create( function()
    createDialog()
    print( "Yield..." )
    coroutine.yield()
    print( "After yield" )
end )

assert( coroutine.resume( co ) )

wx.wxGetApp():MainLoop()


Here is the log I get :
Yield...
Button clicked
Assertion failed: cannot resume running coroutine
stack traceback:
        test.lua:6: in function 'assert'
        test.lua:15: in function <test.lua:13>
        [C]: in function 'yield'
        test.lua:36: in function <test.lua:33>

It seems very weird to me, that something is in the callstack above the 
"yield" call... I've not looked into wxLua source code yet, don't know 
if I'm doing something wrong or if there is some bug here.
Any help would be appreciated...


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to