Hi,

Thanks for your response. But, as i have understand, with that aproach i need 
to subclass wx (affordable) and connect my native app directly with wxWidgets; 
this is not desirable in my case since my app will mostly run in a terminal 
just with a text interface and in certain cases bring up the GUI. Doing that 
would imply that i have to compile against wxWidgets and also the i would have 
one dependency more in the proyect.

I finally solve the problem by doing pooling, my first approach was to use the 
wxEVT_IDLE event handler, but in that case that event only is triggered after a 
diferent one has been triggered (two idle events wont be triggered 
continuosly), i have read a workaround to that, but instead i have opted to 
make a wxTimer and refresh the GUI once or twice a second.

Just for reference a general idea of the architecture (imagine each column 
represents the life of a module):
-----------
| A   | B   |
|    1->     | C  
|     |    2->-------| D
|    5->    |  3 ->------|
|     |    6->    <-4    |
|     |       |------|-------|
--------------
 


Where A and B are two threads from the C++ app, A generates data and B is the 
thread where the Lua interpreter runs (C).
C is the Lua interpreter executed in the B thread. The Lua script loads wxLua 
(D). 

1, 2 and 3 are the order of creation of each component. Once all is up and 
running new data is generated (5), and procesed in the lua script (6), at the 
same time events from the interface (D) can also call the Luainterpreter (C).

By doing pooling with the timer the step 6 is done in the opposite direction, 
so no issues in accesing simultaneously from two threads to the lua state; 
while avoiding dependencies in the native code (if other interface is desired 
just changing the lua script will work).


A snipet if the code to solve the issue:
---------------------------------------

local frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "Example", wx.wxDefaultPosition, 
wx.wxSize(800, 600));
local timer = wx.wxTimer(frame);

frame:Connect(wx.wxEVT_CLOSE_WINDOW,    function ( event )
                                                                            
print("Closing app");
                                                                            
wx.wxGetApp():ExitMainLoop();
                                                                        end);

frame:Connect(wx.wxEVT_TIMER,   function ( event )
                                                        print("Timer event");
                                                    end);

timer:Start(1000);

frame:Show(true);

wx.wxGetApp():MainLoop();

----------------------------------------------

Anyway, thanks for the response.

Best regards.
Javi




>________________________________
> De: John Labenski <jlaben...@gmail.com>
>Para: Javier Mr <javiersdevm...@ymail.com>; wxlua-users@lists.sourceforge.net 
>Enviado: Martes 9 de abril de 2013 6:11
>Asunto: Re: [wxlua-users] Asyncronous updates
> 
>On Mon, Apr 8, 2013 at 7:23 AM, Javier Mr <javiersdevm...@ymail.com> wrote:
>> Hi,
>>
>> i'm getting a crash when running my app and i wonder if i'm doing it wrong.
>>
>> The situation is like this:
>> I have a native C++ application wich has a Lua interpreter embedded. This
>> embedded interpreter load a lua script that contains wxLua. The idea is, the
>> native code is multithraeded a modifies interal structures (protected with
>> mutex) and i want to observe that values so i load the lua script with
>> wxLua.
>
>This sounds reasonable.
>
>> I think my problem is that my native app do call the lua state to notify
>> that changes to the internal data have occur, and the same?¿ lua state is
>> called by wx as callbacks to the GUI events, could be this the reason for
>> crash? Is there a way to avoid this? Not ideal but would be OK to do pooling
>
>Neither Lua or wxWidgets/wxLua are threadsafe (way too much overhead).
>I believe it is possible, but I wouldn't recommend running the GUI in
>a single secondary thread, I would reserve the main thread for that.
>
>> in the MainLoop, so i could (every second for example) retrieve the new data
>> from the native side and update the GUI with the current data.
>
>You can use wxPostEvent() to asynchronously send a message from other
>threads to the GUI thread (though a wxWindow derived class perhaps)
>notifying them that there is new data to show. You can send any
>derived wxEvent class and wxEventType (wxEVT_COMMAND_ENTER) you like
>and use the ID to discriminate your event from anything else.
>Depending on the size of the data you could even put it into the
>wxString member of a wxCommandEvent.
>
>Regards,
>    John
>
>
>

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
wxlua-users mailing list
wxlua-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Reply via email to