seed r458 - trunk/libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r458 - trunk/libseed
- Date: Sun, 14 Dec 2008 08:23:46 +0000 (UTC)
Author: racarr
Date: Sun Dec 14 08:23:45 2008
New Revision: 458
URL: http://svn.gnome.org/viewvc/seed?rev=458&view=rev
Log:
Add interface around rl_bind_key.
Modified:
trunk/libseed/seed-builtins.c
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Sun Dec 14 08:23:45 2008
@@ -23,6 +23,7 @@
#include <readline/readline.h>
#include <readline/history.h>
#include <string.h>
+#include <sys/mman.h>
static JSValueRef
seed_include(JSContextRef ctx,
@@ -103,6 +104,60 @@
return JSValueMakeNull(ctx);
}
+static void
+seed_handle_rl_closure(ffi_cif * cif,
+ void * result,
+ void ** args,
+ void * userdata)
+{
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group,
+ 0);
+ JSValueRef exception = 0;
+ JSObjectRef function = (JSObjectRef) userdata;
+
+ JSObjectCallAsFunction(ctx, function, 0, 0, 0, &exception);
+ if (exception)
+ {
+ gchar *mes = seed_exception_to_string(ctx,
+ exception);
+ g_warning("Exception in readline bind key closure. %s \n", mes, 0);
+ }
+ JSGlobalContextRelease((JSGlobalContextRef)ctx);
+}
+
+static ffi_closure * seed_make_rl_closure(JSObjectRef function)
+{
+ ffi_cif * cif;
+ ffi_closure *closure;
+ ffi_arg result;
+ ffi_status status;
+
+ cif = g_new0(ffi_cif, 1);
+ closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE |
+ PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
+ ffi_prep_cif(cif, FFI_DEFAULT_ABI, 0, &ffi_type_sint, 0);
+ ffi_prep_closure(closure, cif, seed_handle_rl_closure, function);
+
+ return closure;
+}
+
+static JSValueRef
+seed_readline_bind(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ 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]);
+
+ rl_bind_key(*key, (Function*)c);
+
+ g_free(key);
+
+ return JSValueMakeNull(ctx);
+}
+
static JSValueRef
seed_readline(JSContextRef ctx,
JSObjectRef function,
@@ -316,6 +371,8 @@
"fork", &seed_fork, obj);
seed_create_function(local_eng->context,
"quit", &seed_quit, obj);
+ seed_create_function(local_eng->context,
+ "readline_bind", &seed_readline_bind, obj);
arrayObj = JSObjectMake(local_eng->context, NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]