seed r663 - in trunk: libseed tests/javascript
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r663 - in trunk: libseed tests/javascript
- Date: Mon, 5 Jan 2009 11:06:10 +0000 (UTC)
Author: racarr
Date: Mon Jan 5 11:06:10 2009
New Revision: 663
URL: http://svn.gnome.org/viewvc/seed?rev=663&view=rev
Log:
Add support for GValue arguments, with a heuristic for giving the type,
or the ability to force the type (i.e. [GObject.TYPE_INT, 3.3]), will
force the casting, where GObject casting would fail.
Added:
trunk/tests/javascript/gvalue-argument.js (contents, props changed)
Modified:
trunk/libseed/seed-types.c
trunk/tests/javascript/Makefile.am
Modified: trunk/libseed/seed-types.c
==============================================================================
--- trunk/libseed/seed-types.c (original)
+++ trunk/libseed/seed-types.c Mon Jan 5 11:06:10 2009
@@ -119,6 +119,8 @@
if (g_type_info_get_tag(param_type) == GI_TYPE_TAG_UTF8)
g_strfreev(arg->v_pointer);
+ else if (g_type_info_get_tag(param_type) == GI_TYPE_TAG_GTYPE)
+ g_free(arg->v_pointer);
else
g_assert_not_reached();
@@ -147,6 +149,14 @@
G_OBJECT(arg->v_pointer)->ref_count);
g_object_unref(G_OBJECT(arg->v_pointer));
}
+ else if (gtype == G_TYPE_VALUE)
+ {
+ GValue * gval = (GValue *)arg->v_pointer;
+ // Free/unref the GValue's contents.
+ g_value_unset(gval);
+ // Free the GValue.
+ g_slice_free1(sizeof(GValue), gval);
+ }
g_base_info_unref(interface_info);
}
@@ -224,6 +234,24 @@
*array_p = result;
}
+ if (element_type == GI_TYPE_TAG_GTYPE)
+ {
+ GType *result;
+ guint i;
+
+ result = g_new0(GType, length + 1);
+
+ for (i = 0; i < length; i++)
+ {
+ JSValueRef elem = JSObjectGetPropertyAtIndex(ctx,
+ (JSObjectRef) array,
+ i,
+ exception);
+ result[i] = seed_value_to_int(ctx, elem, exception);
+ }
+
+ *array_p = result;
+ }
else
{
seed_make_exception(ctx, exception, "ArgumentError",
@@ -361,6 +389,19 @@
g_base_info_unref(interface);
return FALSE;
}
+ else if (type == G_TYPE_VALUE)
+ {
+ GValue * gval = g_slice_alloc0(sizeof(GValue));
+ seed_gvalue_from_seed_value(ctx,
+ value,
+ (GType)NULL,
+ gval,
+ exception);
+ arg->v_pointer = gval;
+
+ g_base_info_unref(interface);
+ break;
+ }
// Automatically convert between functions and
// GClosures where expected.
else if (g_type_is_a(type, G_TYPE_CLOSURE))
@@ -462,6 +503,7 @@
else
{
GITypeInfo *param_type;
+ //TODO: FIXME: Better array test like the cool one on reddit.
guint length =
seed_value_to_int(ctx, seed_object_get_property(ctx,
(JSObjectRef) value,
@@ -796,8 +838,44 @@
return TRUE;
}
default:
- {
- switch (JSValueGetType(ctx, val))
+ {
+ // TODO: FIXME: This whole undefined type area
+ // needs some heaaavy improvement.
+
+ // Support [GObject.TYPE_INT, 3]
+ // TODO: FIXME: Might crash.
+ if (type == 0 && JSValueIsObject(ctx, val))
+ {
+ // TODO: FIXME: Better array test like the cool one on reddit.
+ guint length =
+ seed_value_to_int(ctx,
+ seed_object_get_property(ctx,
+ (JSObjectRef) val,
+ "length"),
+ exception);
+
+ if (length)
+ {
+ type = seed_value_to_int(ctx,
+ JSObjectGetPropertyAtIndex(ctx,
+ (JSObjectRef) val,
+ 0, exception),
+ exception);
+ val = JSObjectGetPropertyAtIndex(ctx,
+ (JSObjectRef) val,
+ 1, exception);
+ if (type) // Prevents recursion.
+ {
+ return seed_gvalue_from_seed_value(ctx, val,
+ type, ret,
+ exception);
+ }
+ // TODO: FIXME: Handle better?
+ else
+ g_assert_not_reached();
+ }
+ }
+ switch (JSValueGetType(ctx, val))
{
case kJSTypeBoolean:
{
Modified: trunk/tests/javascript/Makefile.am
==============================================================================
--- trunk/tests/javascript/Makefile.am (original)
+++ trunk/tests/javascript/Makefile.am Mon Jan 5 11:06:10 2009
@@ -6,10 +6,12 @@
closure-finalization.js \
c-module.js \
compare.js \
+ gvalue-argument.js \
constructor-args.js \
constructor-prototype.js \
enum.js \
fork.js \
+ array-gtype.js \
function-info.js \
gdk-event.js \
gerror.js \
Added: trunk/tests/javascript/gvalue-argument.js
==============================================================================
--- (empty file)
+++ trunk/tests/javascript/gvalue-argument.js Mon Jan 5 11:06:10 2009
@@ -0,0 +1,16 @@
+#!/usr/bin/env seed
+// Returns: 0
+// STDIN:
+// STDOUT:
+// STDERR:
+Seed.import_namespace("Gtk");
+Gtk.init(null, null);
+
+var s = new Gtk.ListStore();
+
+s.set_column_types(2, [GObject.TYPE_STRING, GObject.TYPE_INT]);
+var iter = new Gtk.TreeIter();
+
+s.append(iter);
+s.set_value(iter, 0, "Hi");
+s.set_value(iter, 1, [GObject.TYPE_INT, 10]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]