Re: libseed-list interpreter, reading stdout



It seems that GLib.set_print_handler and family actually does work, except that Seeds 'print' builtin doesn't use g_print() but puts().

This patch fixes it, and makes it consistent with 'printerr' (which already uses g_printerr()).

diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 41e1d5a..6bd84da 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -225,7 +225,7 @@ seed_print (JSContextRef ctx,

   buf = seed_value_to_string (ctx, arguments[0], exception);

-  puts (buf);
+  g_print ("%s\n", buf);
   g_free (buf);

   return JSValueMakeUndefined (ctx);


Alan Knowles wrote:
I ended up giving up when doing something similar.

Since I was doing all sorts of GIR calls, I would often segfault the whole application by running the wrong thing in the sandbox.

I ended up using a vte,  and running another instance of seed and using a temporary file..
http://devel.akbkhome.com/seed/Vte.html

Regards
Alan

--- On 29/Jun/2010, Jonatan Liljedahl wrote:
Hi,
I'm making an interpreter program that creates a gtk window with a textview for log output, and listens on stdin. Every line that comes in is appended to a buffer until ^E is encountered, then the buffer is evaluated.

I use this as a plugin for gedit, so that I can select text in a document and evaluate it in the seed interpreter while it's running, and since it's running a gtk mainloop I can use all stuff that needs this, like creating windows, setting up timers, etc "live".. (Right now it also parses the code through my AlgoScript parser, but it would be easy to bypass this for a flexible seed live-coding environment.)

Now to the problem, for print() I can simply set ctx.global.print = myprint, where the latter is a function that appends text to the log window instead. But this doesn't work in all cases, since any imported module gets the default original print function in their context again, and also any errors or warnings printed from the C code still gets to stdout.. (like g_warning())

One solution would be to use GLib.set_print_handler(), set_printerr_handler() and set_log_handler(), but these doesn't seem to work (probably needs some wrapper to call a supplied JS callback).

So instead I want to just capture stdout, which would work for everything. I know how to capture stdout from a child process, but how do I capture my own stdout? I tried stuff like this:

//var fd = os.dup(1);
var fd = 1;
var stdout = GLib.io_channel_unix_new(fd);
GLib.io_channel_set_flags(stdout,GLib.IOFlags.NONBLOCK);
GLib.io_add_watch(stdout, 0, GLib.IOCondition.IN, function(source, condition, data) {
     var x = new GLib.String;
     GLib.io_channel_read_line_string(source,x);
     _print(x.str);
     return true;
});

But all I can make it do is to redirect everything from stdin to this watcher (why this happens I don't understand), still triggering my stdin-watcher but only giving it empty strings..

/Jonatan
_______________________________________________
libseed-list mailing list
libseed-list gnome org
http://mail.gnome.org/mailman/listinfo/libseed-list

_______________________________________________
libseed-list mailing list
libseed-list gnome org
http://mail.gnome.org/mailman/listinfo/libseed-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]