[seed] Add printerr
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] Add printerr
- Date: Fri, 22 Jan 2010 01:36:41 +0000 (UTC)
commit 59ff5495fb88023a3bcf615cc2e9499b54caec7b
Author: Matt Arsenault <arsenm2 rpi edu>
Date: Wed Jan 6 12:34:59 2010 -0500
Add printerr
libseed/seed-builtins.c | 33 +++++++++++++++++++++++++++++++++
libseed/seed-builtins.h | 1 +
libseed/seed-engine.c | 10 ++++++----
3 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 5821ad0..58b1159 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -24,6 +24,7 @@
#include <signal.h>
JSValueRef seed_print_ref;
+JSValueRef seed_printerr_ref;
static JSValueRef
seed_include (JSContextRef ctx,
@@ -230,6 +231,31 @@ seed_print (JSContextRef ctx,
return JSValueMakeUndefined (ctx);
}
+static JSValueRef
+seed_printerr (JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef *exception)
+{
+ gchar *buf;
+ if (argumentCount != 1)
+ {
+ seed_make_exception (ctx, exception, "ArgumentError",
+ "printerr expected 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull (ctx);
+ }
+
+ buf = seed_value_to_string (ctx, arguments[0], exception);
+
+ g_printerr ("%s\n", buf);
+ g_free (buf);
+
+ return JSValueMakeUndefined (ctx);
+}
+
const gchar *
seed_g_type_name_to_string (GITypeInfo * type)
{
@@ -487,6 +513,13 @@ seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
seed_print_ref);
JSValueProtect (local_eng->context, seed_print_ref);
+ seed_printerr_ref =
+ JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_printerr);
+ seed_object_set_property (local_eng->context, obj, "printerr", seed_printerr_ref);
+ seed_object_set_property (local_eng->context, local_eng->global, "printerr",
+ seed_printerr_ref);
+ JSValueProtect (local_eng->context, seed_printerr_ref);
+
seed_create_function (local_eng->context,
"check_syntax", &seed_check_syntax, obj);
seed_create_function (local_eng->context,
diff --git a/libseed/seed-builtins.h b/libseed/seed-builtins.h
index f27462c..09285b1 100644
--- a/libseed/seed-builtins.h
+++ b/libseed/seed-builtins.h
@@ -23,6 +23,7 @@
#include "seed-private.h"
extern JSValueRef seed_print_ref;
+extern JSValueRef seed_printerr_ref;
void seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv);
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 6e02230..1f0e7ae 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -69,7 +69,7 @@ static const GDebugKey seed_debug_keys[] = {
};
#endif /* SEED_ENABLE_DEBUG */
-static bool
+static bool
seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
JSValueRef possible_instance, JSValueRef* exception)
{
@@ -78,7 +78,7 @@ seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
!JSValueIsObject (ctx, possible_instance) ||
!JSValueIsObjectOfClass (ctx, possible_instance, gobject_class))
return FALSE;
-
+
constructor_type = (GType) JSObjectGetPrivate (constructor);
value_type = G_OBJECT_TYPE ((GObject *)
JSObjectGetPrivate ((JSObjectRef) possible_instance));
@@ -104,6 +104,7 @@ seed_prepare_global_context (JSContextRef ctx)
seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
seed_object_set_property (ctx, global, "Seed", seed_obj_ref);
seed_object_set_property (ctx, global, "print", seed_print_ref);
+ seed_object_set_property (ctx, global, "printerr", seed_printerr_ref);
JSEvaluateScript (ctx, defaults_script, NULL, NULL, 0, NULL);
@@ -1343,7 +1344,7 @@ seed_engine_destroy (SeedEngine *eng)
JSValueUnprotect (eng->context, eng->global);
JSGlobalContextRelease (eng->context);
JSContextGroupRelease (eng->group);
-
+
g_free (eng);
}
@@ -1375,7 +1376,7 @@ seed_init_with_context_group (gint * argc,
SEED_NOTE (MISC, "failed to parse arguments.");
return FALSE;
}
-
+
if (seed_arg_print_version)
{
g_print("%s\n", "Seed " VERSION);
@@ -1469,3 +1470,4 @@ seed_init (gint * argc, gchar *** argv)
return seed_init_with_context_group (argc, argv, context_group);
}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]