Last active
January 29, 2016 05:08
-
-
Save darkoverlordofdata/6ad7694a07a9332a04d0 to your computer and use it in GitHub Desktop.
Vala Tutorial: Variable-Length_Argument_Lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Varargs.vala | |
* | |
* @see https://wiki.gnome.org/Projects/Vala/Tutorial#Variable-Length_Argument_Lists | |
* | |
* | |
* valac Varargs.vala | |
* ./Varargs | |
* | |
*/ | |
class Actor1 { | |
public void animate(int fixed, ...) { | |
var l = va_list(); | |
while (true) { | |
string? key = l.arg(); | |
if (key == null) { | |
break; // end of the list | |
} | |
double val = l.arg(); | |
stdout.printf("%s: %g\n", key, val); | |
} | |
} | |
} | |
class Actor2 { | |
public void animate(int fixed, ...) { | |
var l = va_list(); | |
while (true) { | |
string? key = l.arg(); | |
if (key == null) { | |
break; // end of the list | |
} | |
double val = l.arg(); | |
stdout.printf("%s: %g\n", key, val); | |
} | |
} | |
} | |
public static int main(string[] args) { | |
var actor1 = new Actor1(); | |
stdout.printf("string - double argument pairs\n"); | |
actor1.animate (3000, "x", 100.0, "y", 200.0, "rotation-angle-z", 500.0, "opacity", 0.0); | |
/* Output - | |
string - double argument pairs | |
x: 100 | |
y: 200 | |
rotation-angle-z: 500 | |
opacity: 0 | |
*/ | |
var actor2 = new Actor2(); | |
stdout.printf("Alternate\n"); | |
actor2.animate (3000, x: 100.0, y: 200.0, rotation_angle_z: 500.0, opacity: 0.0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment