Commit 150c1e58 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter

Support emitting signals with return values, patch by Samuel

2008-06-15  Jürg Billeter  <j@bitron.ch>

	* gobject/valaccodeinvocationexpressionbinding.vala:

	Support emitting signals with return values,
	patch by Samuel Cormier-Iijima, fixes bug 537323

	* tests/classes-signals.exp:
	* tests/classes-signals.vala:

	Test signals with return values

svn path=/trunk/; revision=1589
parent cd4c6131
2008-06-15 Jürg Billeter <j@bitron.ch>
* gobject/valaccodeinvocationexpressionbinding.vala:
Support emitting signals with return values,
patch by Samuel Cormier-Iijima, fixes bug 537323
* tests/classes-signals.exp:
* tests/classes-signals.vala:
Test signals with return values
2008-06-15 Jürg Billeter <j@bitron.ch>
* vala/valascanner.vala:
......
......@@ -43,6 +43,7 @@ Rob Taylor
Roberto Majadas
Roland Hostettler
Ross Burton
Samuel Cormier-Iijima
Stéphan Kochen
Thijs Vermeir
Travis Watkins
......
......@@ -386,6 +386,26 @@ public class Vala.CCodeInvocationExpressionBinding : CCodeExpressionBinding {
}
}
// pass address for the return value of non-void signals without emitter functions
if (itype is SignalType && !(itype.get_return_type () is VoidType)) {
var sig = ((SignalType) itype).signal_symbol;
if (!sig.has_emitter) {
var temp_var = codegen.get_temp_variable (itype.get_return_type ());
var temp_ref = new CCodeIdentifier (temp_var.name);
codegen.temp_vars.insert (0, temp_var);
carg_map.set (codegen.get_param_pos (-1, true), new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, temp_ref));
var ccomma = new CCodeCommaExpression ();
ccomma.append_expression ((CCodeExpression) ccall_expr);
ccomma.append_expression ((CCodeExpression) temp_ref);
ccall_expr = ccomma;
}
}
// append C arguments in the right order
int last_pos = -1;
int min_pos;
......
Signal Test: 1 2 3 4 5 6 7 8 9 10
User Signal Test: 1 2 3 4 5 6
Signal Return Test: 1 2 3 4 5 6 7 8
......@@ -62,6 +62,13 @@ class Maman.Bar : Object {
stdout.printf (" 6\n");
stdout.printf ("Signal Return Test: 1");
var return_bar = new ReturnBar ();
return_bar.run ();
stdout.printf (" 8\n");
return 0;
}
}
......@@ -92,3 +99,31 @@ class Maman.UserBar : Object {
}
}
class Maman.ReturnFoo : Object {
public signal int int_activated (int arg);
public signal string string_activated (string arg);
}
class Maman.ReturnBar : Object {
public void run () {
stdout.printf (" 2");
var foo = new ReturnFoo ();
foo.int_activated += (foo, arg) => {
stdout.printf (" %d", arg);
return arg + 1;
};
foo.string_activated += (foo, arg) => {
stdout.printf (arg);
return " 6";
};
stdout.printf (" %d", foo.int_activated (3));
stdout.printf (foo.string_activated (" 5"));
stdout.printf (" 7");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment