John Labenski a écrit :
> I think that all you need to do is to shuffle around your existing
> code to pull out the dialog creation from the coroutine code, I also
> demonstrate how to pass data around without using globals.
Yes, this is a solution, but I would like to avoid it if possible. My
idea is to use coroutines to have a flexible system that would allow
sequential programming to perform tasks even when these tasks require
user action, or waiting for anything without blocking the application.
The promptUser function is only an example. I'd like to be able to write
things like:
local filename = openFileDialog()
if filename ~= nil then
if string.sub( filename, -10 ) == ".something" then
local choice = promptUser( "Are you sure?" )
if choice then
-- do something with filename
end
else
-- do something else with filename
end
end
And this piece of code could happen to be deap inside a coroutine
callstack, so the main thread that started it do not know it needed to
create dialogs and connect events before starting the coroutine.
> Alternatively, you can do exactly what you had before and simply
> connect to the button after you create the dialog in the coroutine.
> wxWidgets doesn't care or know what coroutine you're in since they're
> all in the same C thread.
I don't understand what you mean here. I think it is exactly what I've
done in my first example, but it doesn't work, because after connecting
my callback on the button, I yield, and the callback is executed in the
coroutine stack (which is the part I didn't understand in my first
e-mail), so the callback registered from the coroutine can not resume
the same coroutine.
>
> Or, you can use the code you originally had, but use wxPostEvent(...)
> to send your own event from the Lua coroutine back to a function
> created and connected in the main thread.
If I understand correctly, this would allow me to execute code in the
main thread from my coroutine ? I will look further into this, it could
solve my problem.
>
> Finally, if all you're doing is trying to create dialogs to get user
> input you wouldn't bother with coroutines since wxWidgets has an event
> loop. The only use of a coroutine would be for some long calculation,
> but again this is usually performed with idle events (wxEVT_IDLE) to
> allow the GUI to refresh.
I don't want to use coroutines to execute things in parallel, but only
to have nice and easily readable code as the example at the beginning of
this e-mail.
>
> You can create dozens and dozens of GUI elements with no noticeable
> lag. You may notice that on a very slow machine the controls.wx.lua
> may be slow to start, but that is because we are connecting to every
> imagineable event for every control created. It is not a realistic
> benchmark.
Ok :-)
> Regards,
> John
>
Thanks again for the answers. I think now I have enough solutions to
pick one that suit my needs in my real application :-)
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/wxlua-users