On 04.07.2010, at 13:48, Alexander Walz wrote:
> Dear FLTK community,
>
> I would like to integrate the test/editor.cxx editor shipped with FLTK 1.1 
> with a
> programming language based on Lua 5.1.

which exact FLTK version (e.g. 1.1.10) ?
which OS ?

> I would like to display strings generated by Lua in real-time in a 
> Fl_Text_Display or
> Fl_Browser object.
>
> My Lua programmes sometimes consume a lot of computing power but should write 
> any intermediate
> results of the calculations immediately in a FLTK window.
>
> However, only after the whole computation finishes, the output is displayed. 
> Even the
> title bar of the output window appears after the computation ends.
>
> Any calls to redisplay, redraw, Fl::flush, show(int line), etc. failed.

For creating and showing windows, Fl::flush() is probably not enough.
You should try Fl::wait(0.5) and/or Fl::check(). See below for more...

> Object-oriented programming is new to me, as is GUI programming, so please be 
> patient
> with me. I have not programmed any `update output` callback function yet.

The asynchronous way of GUI programming can be difficult at first...

> Would you please help me ?

Will try ...

> Here is the code:

--- snipped ---

> /* open a new window, and pass any text entered to the interpreter to 
> luaL_loadbuffer; luaL_loadbuffer finally runs the `print` function (if 
> entered by the user) via the C aux_printnonstruct procedure (see above) */
> void execute_cb (Fl_Widget*, void*) {  /* 0.34.0 */
>    int error;
>    const char *buffer;
>    Fl_Window *win = new Fl_Window(640, 480);
>    buff = new Fl_Text_Buffer();
>    disp = new Fl_Text_Display(0, 20, 640, 480, "Output");
>    disp->buffer(buff);
>    win->resizable(*disp);
>    win->show();

FLTK needs to read the system messages related to creation of windows
at this point, thus Fl::flush() is not enough. You need Fl::check()
or even Fl::wait() here. If you're on Linux (X11) this might be even
more difficult. For a first shot, try this:

   Fl::wait(0.2);
   Fl::wait(0.2);
   Fl::wait(0.2);

Yes, I mean three times the same statement. Just to see if/how it
works ...

Note: On Windows, a single Fl::wait() or Fl::check() may be enough,
but on Linux/X11 things may be different.

>    buffer = textbuf->text();
>    error = luaL_loadbuffer(L, buffer, strlen(buffer), "line") || lua_pcall(L, 
> 0, 0, 0);
>    if (error) {
>      buff->text(lua_tostring(L, -1));
>      agn_poptop(L);
>    }
> }

I can't see what the long computation would be, and how the display
update is programmed, but here is how it should work:

Whenever you want to change the display, do something like this:

   buff->append(text);  // append or set text in buffer
   disp->insert_position(buff->length); // set insert position
   disp->show_insert_position(); // scroll to end of buffer
   disp->redraw();      // redraw the associated Fl_Text_Display
   Fl::check();         // give FLTK the opportunity to do it now

Some of the disp->... operations might not be necessary, but
I hope that you get the idea. The code is untested, though...

If you can't get it going, please try with a simple complete
example that can be compiled in one file. You can simulate the
long computation with some sleep() or Sleep() calls. If you
need more help, post your simple example here, and we can see
what's wrong and help you better.

Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to