seed r482 - in trunk: examples libseed



Author: racarr
Date: Tue Dec 16 01:15:15 2008
New Revision: 482
URL: http://svn.gnome.org/viewvc/seed?rev=482&view=rev

Log:
Add Seed.spawn. Change server to cowsay server.

Modified:
   trunk/examples/Gnio-server.js
   trunk/libseed/seed-builtins.c

Modified: trunk/examples/Gnio-server.js
==============================================================================
--- trunk/examples/Gnio-server.js	(original)
+++ trunk/examples/Gnio-server.js	Tue Dec 16 01:15:15 2008
@@ -5,7 +5,7 @@
 // I don't think this is the right way of doing things.
 var r = new Gnio.Resolver();
 var sock = new Gnio.Socket({domain: Gnio.SocketDomain.inet,
-						type: Gnio.SocketType.stream});
+						    type: Gnio.SocketType.stream});
 
 
 var addr = r.lookup_name("localhost");
@@ -26,13 +26,14 @@
 
 while(1)
 {
-	line = ds.read_line(null);
+	var line = ds.read_line(null);
+    var cowsay = Seed.spawn("cowsay " + line);
 	if (line.search("quit") > -1)
 	{
 		client.close();
 		Seed.quit();
 	}
-	os.put_string(line);
+	os.put_string(cowsay.stdout);
 	os.put_string("\n");
 }
 

Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c	(original)
+++ trunk/libseed/seed-builtins.c	Tue Dec 16 01:15:15 2008
@@ -341,6 +341,48 @@
 }
 
 static JSValueRef
+seed_spawn(JSContextRef ctx,
+		  JSObjectRef function,
+		  JSObjectRef this_object,
+		  size_t argumentCount,
+		  const JSValueRef arguments[], JSValueRef * exception)
+{
+	gchar *line, *stdout, *stderr;
+	JSObjectRef ret;
+	GError *error = NULL;
+
+	if (argumentCount != 1)
+	{
+		// I am so lazy
+		seed_make_exception(ctx, exception, "ArgumentError", 
+							"Seed.spawn expected 1 argument");
+		return JSValueMakeNull(ctx);
+	}
+
+	line = seed_value_to_string(ctx, arguments[0], exception);
+	g_spawn_command_line_sync(line, &stdout, &stderr, NULL, &error);
+	if (error)
+	{
+		seed_make_exception_from_gerror(ctx, exception, error);
+
+		g_free(line);
+		g_error_free(error);
+		return JSValueMakeNull(ctx);
+	}
+	
+	ret = JSObjectMake(ctx, NULL, NULL);
+	seed_object_set_property(ctx, ret, "stdout",
+							 seed_value_from_string(ctx, stdout, exception));
+	seed_object_set_property(ctx, ret, "stderr",
+							 seed_value_from_string(ctx, stderr, exception));
+
+	g_free(stdout);
+	g_free(stderr);
+
+	return ret;	
+}
+
+static JSValueRef
 seed_quit(JSContextRef ctx,
 		  JSObjectRef function,
 		  JSObjectRef this_object,
@@ -385,6 +427,8 @@
 	seed_create_function(local_eng->context, 
 						 "fork", &seed_fork, obj);
 	seed_create_function(local_eng->context, 
+						 "spawn", &seed_spawn, obj);
+	seed_create_function(local_eng->context, 
 						 "quit", &seed_quit, obj);
 	seed_create_function(local_eng->context, 
 						 "readline_bind", &seed_readline_bind, obj);



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