seed r125 - in trunk: examples libseed
- From: racarr svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r125 - in trunk: examples libseed
- Date: Wed, 5 Nov 2008 11:43:06 +0000 (UTC)
Author: racarr
Date: Wed Nov 5 11:43:05 2008
New Revision: 125
URL: http://svn.gnome.org/viewvc/seed?rev=125&view=rev
Log:
Implement return types from native closures. Make example with clutter
alpha.
Modified:
trunk/examples/clutter.js
trunk/libseed/seed-closure.c
Modified: trunk/examples/clutter.js
==============================================================================
--- trunk/examples/clutter.js (original)
+++ trunk/examples/clutter.js Wed Nov 5 11:43:05 2008
@@ -16,6 +16,22 @@
"LemonChiffon2",
"RosyBrown3"];
+function alpha_func(alpha)
+{
+ try
+ {
+ timeline = alpha.get_timeline();
+ frame = timeline.get_current_frame();
+ n_frames = timeline.num_frames;
+
+ return (frame * Clutter.ALPHA_MAX_ALPHA)/n_frames;
+ }
+ catch (e)
+ {
+ Seed.print(e.message);
+ }
+}
+
var stage = new Clutter.Stage();
var timeline = new Clutter.Timeline({fps:60, num_frames:300});
stage.show_all();
@@ -66,7 +82,7 @@
font_name:"Bitstream Vera Sans 40"});
var fadeline = new Clutter.Timeline({fps:60, num_frames:200});
var effect = Clutter.EffectTemplate._new(timeline,
- Clutter.sine_inc_func);
+ alpha_func);
text.show();
stage.add_actor(text);
Modified: trunk/libseed/seed-closure.c
==============================================================================
--- trunk/libseed/seed-closure.c (original)
+++ trunk/libseed/seed-closure.c Wed Nov 5 11:43:05 2008
@@ -118,12 +118,16 @@
SeedClosurePrivates * privates = userdata;
int num_args, i;
JSValueRef * jsargs;
- JSValueRef * return_value;
+ JSValueRef return_value;
+ GITypeTag return_tag;
GIArgInfo * arg_info;
GITypeInfo * return_type;
GArgument rarg;
+ GArgument * return_arg = g_new0(GArgument, 1);
num_args = g_callable_info_get_n_args(privates->info);
+ return_type = g_callable_info_get_return_type(privates->info);
+ return_tag = g_type_info_get_tag(return_type);
jsargs = (JSValueRef *)g_new0(JSValueRef, num_args);
for (i = 0; i < num_args; i++)
@@ -183,7 +187,7 @@
arg->v_double = *(gdouble*)args[i];
break;
case GI_TYPE_TAG_UTF8:
- arg->v_string = (gchar *)args[i];
+ arg->v_string = *(gchar **)args[i];
break;
case GI_TYPE_TAG_INTERFACE:
{
@@ -218,8 +222,91 @@
jsargs[i] = seed_gi_argument_make_js(arg, arg_type, 0);
}
- JSObjectCallAsFunction(eng->context, (JSObjectRef)privates->function,
+ return_value = (JSValueRef)
+ JSObjectCallAsFunction(eng->context, (JSObjectRef)privates->function,
0, num_args, jsargs, 0);
+
+ seed_gi_make_argument((JSValueRef)return_value, return_type,
+ return_arg, 0);
+ switch (return_tag)
+ {
+
+ case GI_TYPE_TAG_BOOLEAN:
+ *(gboolean*)result = return_arg->v_boolean;
+ break;
+ case GI_TYPE_TAG_INT8:
+ *(gint8*)result = return_arg->v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ *(guint8*)result = return_arg->v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ *(gint16*)result = return_arg->v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ return_arg->v_uint16 = *(guint16*)args[i];
+ break;
+ case GI_TYPE_TAG_INT32:
+ *(gint32*)result = return_arg->v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ *(guint32*)result = return_arg->v_uint32;
+ break;
+ case GI_TYPE_TAG_LONG:
+ case GI_TYPE_TAG_INT64:
+ *(glong*)result = return_arg->v_int64;
+ break;
+ case GI_TYPE_TAG_ULONG:
+ case GI_TYPE_TAG_UINT64:
+ *(glong*)result = return_arg->v_uint64;
+ break;
+ case GI_TYPE_TAG_INT:
+ case GI_TYPE_TAG_SSIZE:
+ case GI_TYPE_TAG_SIZE:
+ *(gint*)result = return_arg->v_int32;
+ break;
+ case GI_TYPE_TAG_UINT:
+ *(guint*)result = return_arg->v_uint32;
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ *(gfloat*)result = return_arg->v_float;
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ *(gdouble*)result = return_arg->v_double;
+ break;
+ case GI_TYPE_TAG_UTF8:
+ *(gchar**)result = return_arg->v_string;
+ break;
+ case GI_TYPE_TAG_INTERFACE:
+ {
+ GIBaseInfo *interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(return_type);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT ||
+ interface_type == GI_INFO_TYPE_INTERFACE) {
+ *(gpointer*)result = return_arg->v_pointer;
+ break;
+ }
+
+ else if (interface_type == GI_INFO_TYPE_ENUM ||
+ interface_type == GI_INFO_TYPE_FLAGS) {
+ *(double*)result = return_arg->v_double;
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ *(gpointer*)result = return_arg->v_pointer;
+ break;
+ }
+ }
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ *(gpointer*)result = return_arg->v_pointer;
+ break;
+ default:
+ *(gpointer*)result = 0;
+ }
}
@@ -262,7 +349,7 @@
privates->closure = closure;
ffi_prep_cif(cif, FFI_DEFAULT_ABI, 2,
- &ffi_type_void, arg_types);
+ get_ffi_type(return_type), arg_types);
ffi_prep_closure(closure, cif, seed_handle_closure, privates);
return privates;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]