[seed: 2/4] Add seed_signal_connect and seed_signal_connect_fu



commit c39776b3d6d76076d6a907c3c3da06cf5392fbf8
Author: Robert Carr <racarr mireia (none)>
Date:   Sun Mar 15 09:51:17 2009 -0400

    Add seed_signal_connect and seed_signal_connect_full C convenience API
---
 doc/reference/seed-sections.txt |    6 ++++-
 libseed/seed-api.c              |   44 ++++++++++++++++++++++++++++++++++++++-
 libseed/seed-private.h          |    1 +
 libseed/seed-signals.c          |    5 ++-
 libseed/seed-signals.h          |    9 ++++++++
 libseed/seed.h                  |   15 +++++++++++++
 6 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/doc/reference/seed-sections.txt b/doc/reference/seed-sections.txt
index 3b0d960..454f667 100644
--- a/doc/reference/seed-sections.txt
+++ b/doc/reference/seed-sections.txt
@@ -121,4 +121,8 @@ SeedObjectCallAsFunctionCallback
 SeedObjectHasInstanceCallback
 SeedObjectConvertToTypeCallback
 SeedObjectCallAsConstructorCallback
-</SECTION>
\ No newline at end of file
+</SECTION>
+<SUBSECTION>
+seed_signal_connect
+seed_signal_connect_full
+</SECTION>
diff --git a/libseed/seed-api.c b/libseed/seed-api.c
index cf4300b..551e339 100644
--- a/libseed/seed-api.c
+++ b/libseed/seed-api.c
@@ -274,7 +274,8 @@ seed_evaluate (JSContextRef ctx, SeedScript * s, JSObjectRef this)
  *
  */
 JSValueRef
-seed_simple_evaluate (JSContextRef ctx, gchar * source)
+seed_simple_evaluate (JSContextRef ctx, 
+		      const gchar * source)
 {
   JSValueRef ret;
   JSStringRef script = JSStringCreateWithUTF8CString (source);
@@ -521,3 +522,44 @@ seed_engine_get_search_path (SeedEngine * eng)
 {
   return eng->search_path;
 }
+
+/**
+ * seed_signal_connect_full:
+ * @ctx: A valid #SeedContext
+ * @object: A #GObject, to connect the signal on.
+ * @signal: A signal specification.
+ * @function: The JavaScript function to connect to the signal.
+ * @user_data: An additional parameter to pass to the function.
+ */
+void
+seed_signal_connect_full (JSContextRef ctx,
+			   GObject *object,
+			   const gchar *signal,
+			   JSObjectRef function,
+			   JSObjectRef user_data)			   
+{
+  seed_gobject_signal_connect(ctx, signal, object, function,
+			       NULL, user_data);
+}
+
+/**
+ * seed_signal_connect:
+ * @ctx: A valid #SeedContext
+ * @object: A #GObject, to connect the signal on.
+ * @signal: A signal specification.
+ * @script: The script to connect to the signal. Should be a function.
+ */
+void
+seed_signal_connect (JSContextRef ctx,
+		     GObject *object,
+		     const gchar *signal,
+		     const gchar *script)
+{
+  JSValueRef func;
+  
+  func = seed_simple_evaluate(ctx, script);
+  seed_signal_connect_full(ctx, object, signal, (JSObjectRef)func,
+			   NULL);
+}
+
+
diff --git a/libseed/seed-private.h b/libseed/seed-private.h
index fa7c372..13c7ebc 100644
--- a/libseed/seed-private.h
+++ b/libseed/seed-private.h
@@ -23,6 +23,7 @@
 #define _SEED_PRIVATE_H
 
 #include <stdlib.h>
+#include <sys/types.h>
 #include <JavaScriptCore/JavaScript.h>
 #include <glib.h>
 #include <glib-object.h>
diff --git a/libseed/seed-signals.c b/libseed/seed-signals.c
index a7c3ceb..d0ff9db 100644
--- a/libseed/seed-signals.c
+++ b/libseed/seed-signals.c
@@ -101,12 +101,13 @@ closure_invalidated (gpointer data, GClosure * c)
   JSGlobalContextRelease ((JSGlobalContextRef) ctx);
 }
 
-static void
+void
 seed_gobject_signal_connect (JSContextRef ctx,
 			     const gchar * signal_name,
 			     GObject * on_obj,
 			     JSObjectRef func,
-			     JSObjectRef this_obj, JSObjectRef user_data)
+			     JSObjectRef this_obj, 
+			     JSObjectRef user_data)
 {
   GSignalQuery query;
   GClosure *closure;
diff --git a/libseed/seed-signals.h b/libseed/seed-signals.h
index f2dd3bf..e65cda2 100644
--- a/libseed/seed-signals.h
+++ b/libseed/seed-signals.h
@@ -33,6 +33,15 @@ void seed_signal_marshal_func (GClosure * closure,
 
 void seed_add_signals_to_object (JSContextRef ctx,
 				 JSObjectRef object_ref, GObject * obj);
+
+void seed_gobject_signal_connect (JSContextRef ctx,
+				  const gchar * signal_name,
+				  GObject * on_obj,
+				  JSObjectRef func,
+				  JSObjectRef this_obj, 
+				  JSObjectRef user_data);
+
+
 JSClassDefinition *seed_get_signal_class (void);
 extern JSClassRef gobject_signal_class;
 
diff --git a/libseed/seed.h b/libseed/seed.h
index 847b701..ba5701b 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -346,4 +346,19 @@ SeedObject seed_make_constructor (SeedContext ctx,
 void seed_engine_set_search_path (SeedEngine * eng, gchar ** path);
 gchar **seed_engine_get_search_path (SeedEngine * eng);
 
+void
+seed_signal_connect (SeedContext ctx,
+		     GObject *object,
+		     const gchar *signal,
+		     const gchar *script);
+
+void
+seed_signal_connect_value (SeedContext ctx,
+			   GObject *object,
+			   const gchar *signal,
+			   SeedValue function,
+			   SeedValue user_data);			   
+
+
+
 #endif



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