seed r459 - in trunk: examples libseed



Author: racarr
Date: Sun Dec 14 08:23:47 2008
New Revision: 459
URL: http://svn.gnome.org/viewvc/seed?rev=459&view=rev

Log:
Interface around rl_bind_key.

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

Modified: trunk/examples/repl.js
==============================================================================
--- trunk/examples/repl.js	(original)
+++ trunk/examples/repl.js	Sun Dec 14 08:23:47 2008
@@ -1,12 +1,14 @@
 #!/usr/bin/env seed
-
+history = [];
 with (Seed)
 {
 	while(1)
 	{
 		try
 		{
-			print(eval(readline("> ")));
+			item = readline("> ");
+			history.push(item);
+			print(eval(item));
 		}
 		catch(e)
 		{

Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c	(original)
+++ trunk/libseed/seed-builtins.c	Sun Dec 14 08:23:47 2008
@@ -125,6 +125,8 @@
 	JSGlobalContextRelease((JSGlobalContextRef)ctx);
 }
 
+// "Leaky" in that it exists for lifetime of program,
+// kind of unavoidable though.
 static ffi_closure * seed_make_rl_closure(JSObjectRef function)
 {
 	ffi_cif * cif;
@@ -148,8 +150,21 @@
 			  size_t argumentCount,
 			  const JSValueRef arguments[], JSValueRef * exception)
 {
-	gchar * key = seed_value_to_string(ctx, arguments[0], exception);
-	ffi_closure * c = seed_make_rl_closure((JSObjectRef)arguments[1]);
+	gchar * key;
+	ffi_closure * c;
+
+	if (argumentCount != 2)
+	{
+		gchar *mes =
+			g_strdup_printf("Seed.readline_bind expected 2 arguments, "
+							"got %d", argumentCount);
+		seed_make_exception(ctx, exception, "ArgumentError", mes);
+		g_free(mes);
+		return JSValueMakeNull(ctx);
+	}
+
+	key = seed_value_to_string(ctx, arguments[0], exception);
+	c = seed_make_rl_closure((JSObjectRef)arguments[1]);
 	
 	rl_bind_key(*key, (Function*)c);
 	



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