[Kde-bindings] playground/bindings/kimono

Arno Rehn kde at arnorehn.de
Wed Oct 4 18:00:25 UTC 2006


SVN commit 592406 by arnorehn:

* Now slot return values should work, but didn't test it.

CCMAIL: kde-bindings at kde.org



 M  +4 -0      ChangeLog  
 M  +13 -13    SmokeInvocation.cs  
 M  +43 -9     qyoto.cpp  


--- trunk/playground/bindings/kimono/ChangeLog #592405:592406
@@ -1,3 +1,7 @@
+2006-10-04  Arno Rehn  <arno at arnorehn.de>
+
+	* Now slot return values should work, but didn't test it.
+
 2006-10-03  Arno Rehn  <arno at arnorehn.de>
 
 	* Fixed crash when constructing a QSpacerItem (may need improvement)
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #592405:592406
@@ -496,31 +496,31 @@
 				if (returnType == typeof(void)) {
 					;
 				} else if (returnType == typeof(bool)) {
-					retval->s_bool = (bool) returnValue;
+					retval[0].s_bool = (bool) returnValue;
 				} else if (returnType == typeof(sbyte)) {
-					retval->s_char = (sbyte) returnValue;
+					retval[0].s_char = (sbyte) returnValue;
 				} else if (returnType == typeof(byte)) {
-					retval->s_uchar = (byte) returnValue;
+					retval[0].s_uchar = (byte) returnValue;
 				} else if (returnType == typeof(short)) {
-					retval->s_short = (short) returnValue;
+					retval[0].s_short = (short) returnValue;
 				} else if (returnType == typeof(ushort)) {
-					retval->s_ushort = (ushort) returnValue;
+					retval[0].s_ushort = (ushort) returnValue;
 				} else if (returnType == typeof(int) || returnType.IsEnum) {
-					retval->s_int = (int) returnValue;
+					retval[0].s_int = (int) returnValue;
 				} else if (returnType == typeof(uint)) {
-					retval->s_uint = (uint) returnValue;
+					retval[0].s_uint = (uint) returnValue;
 				} else if (returnType == typeof(long)) {
-					retval->s_long = (long) returnValue;
+					retval[0].s_long = (long) returnValue;
 				} else if (returnType == typeof(ulong)) {
-					retval->s_ulong = (ulong) returnValue;
+					retval[0].s_ulong = (ulong) returnValue;
 				} else if (returnType == typeof(float)) {
-					retval->s_float = (float) returnValue;
+					retval[0].s_float = (float) returnValue;
 				} else if (returnType == typeof(double)) {
-					retval->s_double = (double) returnValue;
+					retval[0].s_double = (double) returnValue;
 				} else if (returnType == typeof(string)) {
-					retval->s_class = (IntPtr) GCHandle.Alloc(returnValue);
+					retval[0].s_class = (IntPtr) GCHandle.Alloc(returnValue);
 				} else {
-					retval->s_class = (IntPtr) GCHandle.Alloc(returnValue);
+					retval[0].s_class = (IntPtr) GCHandle.Alloc(returnValue);
 				}
 			}
 		}
--- trunk/playground/bindings/kimono/qyoto.cpp #592405:592406
@@ -700,6 +700,7 @@
     const char * _slotname;
     int _items;
     MocArgument *_args;
+    MocArgument * _mocret;
     void **_o;
     int _cur;
     bool _called;
@@ -722,11 +723,14 @@
 	void invokeSlot() {
 		if (_called) return;
 		_called = true;
-		Smoke::StackItem* ret = new Smoke::StackItem();
+		Smoke::StackItem* ret = new Smoke::StackItem[1];
 		(*InvokeCustomSlot)(_obj, _slotname, _sp, ret);
 		
-		if (_args[0].argType != xmoc_void) {
-			SlotReturnValue r(_o, ret, _args);
+		if (_mocret[0].argType != xmoc_void) {
+#ifdef DEBUG
+			printf("CREATE SlotReturnValue()\n");
+#endif
+			SlotReturnValue r(_o, ret, _mocret);
 		}
 	}
 
@@ -744,11 +748,12 @@
 		_cur = oldcur;
 	}
 
-    InvokeSlot(void * obj, const char * slotname, int items, MocArgument * args, void** o) :
+    InvokeSlot(void * obj, const char * slotname, int items, MocArgument * args, void** o, MocArgument * mocReturn) :
     _obj(obj), _slotname(slotname), _items(items), _args(args), _o(o), _cur(-1), _called(false)
     {
 		_sp = new Smoke::StackItem[_items];
 		_stack = new Smoke::StackItem[_items];
+		_mocret = mocReturn;
 		copyArguments();
     }
 
@@ -984,8 +989,11 @@
 		name += "*";
 		typeId = qt_Smoke->idType((const char *) name);
 	}
-
+	
 	if (typeId == 0) {
+//#ifdef DEBUG
+		printf("In setMocType(): no typeId\n");
+//#endif
 		return false;
 	}
 
@@ -1033,6 +1041,28 @@
 	return GetMocArgumentsNumber(member, tmp);
 }
 
+MocArgument *
+GetMocReturnType(QString type) {
+	QRegExp rx1("^(bool|int|double|char\\*|QString)&?$");
+	
+	MocArgument * mocargs = new MocArgument[1];
+	
+	if (type != "void" && type != "" && type != " ") {
+		QString t = type;
+		t.replace(QRegExp("^const\\s+"), "");
+		t = (rx1.indexIn(t) == -1) ? "ptr" : rx1.cap(1);
+		//printf("arg: %s t: %s\n", (const char*)type.toLatin1(), (const char*)t.toLatin1());
+		QByteArray t_name = type.toLatin1();
+		QByteArray t_static_type = t.toLatin1();
+		setMocType(mocargs, 0, t_name.constData(), t_static_type.constData());
+	}
+	else {
+		mocargs[0].argType = xmoc_void;
+	}
+	
+	return mocargs;
+}
+
 bool
 SignalEmit(char * signature, void * obj, Smoke::StackItem * sp, int items)
 {
@@ -1072,7 +1102,9 @@
 }
 
 QMetaObject* parent_meta_object(void* obj) {
+#ifdef DEBUG
 printf("In make_metaObject()\n");
+#endif
 	smokeqyoto_object* o = value_obj_info(obj);
 	Smoke::Index nameId = o->smoke->idMethodName("metaObject");
 	Smoke::Index parent_index = o->smoke->classes[o->classId].parents;
@@ -1113,7 +1145,7 @@
 	QMetaObject* meta = new QMetaObject;
 	*meta = tmp;
 
-// #ifdef DEBUG
+#ifdef DEBUG
 	printf("make_metaObject() superdata: %p\n", meta->d.superdata);
 	printf("stringdata: ");
 	for (int j = 0; j < stringdata_count; j++) {
@@ -1130,7 +1162,7 @@
 		printf("%d, ", my_data[i]);
 	}
 	printf("\n");
-// #endif
+#endif
 	
 	// create smoke object
 	smokeqyoto_object* m = (smokeqyoto_object*)malloc(sizeof(smokeqyoto_object));
@@ -1182,7 +1214,8 @@
 	// retrieve method signature from id
 	QMetaMethod method = metaobject->method(_id);
 	QString name(method.signature());
-		
+	QString type(method.typeName());
+	
 	if (method.methodType() == QMetaMethod::Signal) {
 		metaobject->activate(qobj, _id, (void**) _o);
 		return _id - (count - offset);
@@ -1190,9 +1223,10 @@
 
 	int items;
 	MocArgument* mocArgs = GetMocArgumentsNumber(name, items);
+	MocArgument* mocReturn = GetMocReturnType(type);
 	
 	// invoke slot
-	InvokeSlot slot(obj, (const char*)name.toLatin1(), items, mocArgs, (void**)_o);
+	InvokeSlot slot(obj, (const char*)name.toLatin1(), items, mocArgs, (void**)_o, mocReturn);
 	slot.next();
 	
 	delete mocArgs;



More information about the Kde-bindings mailing list