more Vala examples

This commit is contained in:
Kolan Sh 2012-09-30 19:46:05 +04:00
parent 56155f56c9
commit 1326067d6a
6 changed files with 106 additions and 12 deletions

View File

@ -0,0 +1,23 @@
interface IfaceA : Object {
public abstract void method_a ();
}
interface IfaceB : Object, IfaceA {
public abstract void method_b ();
}
class Demo : Object, IfaceA, IfaceB {
public void method_a () { stdout.printf ("a called\n"); }
public void method_b () { stdout.printf ("b called\n"); }
public void method_c () { stdout.printf ("c called\n"); }
static int main ()
{
stdout.printf ("Hello world!\n");
var demo = new Demo ();
demo.method_a ();
demo.method_b ();
demo.method_c ();
return 0;
}
}

20
vala/hello/lock.vala Normal file
View File

@ -0,0 +1,20 @@
/* Vala Lock Example */
using GLib;
public class Sample : GLib.Object {
private int critical_data;
public void inc () {
lock (critical_data) {
critical_data++;
}
}
static void main (string[] args) {
var sample = new Sample ();
sample.inc ();
}
}

10
vala/hello/notify.vala Normal file
View File

@ -0,0 +1,10 @@
public class Demo : Object {
public string title { get; set; }
}
void main () {
var demo = new Demo ();
demo.notify.connect ((s, p) => stdout.printf ("Property %s changed\n", p.name));
demo.title = "hello";
demo.title = "world";
}

View File

@ -0,0 +1,17 @@
int main ()
{
int[] a = {1, 2, 3};
double b = 5.33;
var s ="Hello, %s\n";
stdout.printf (s, b.to_string());
a[8] = 7;
foreach (int i in a)
{
stdout.printf ("%d\n", i);
}
return 0;
}

23
vala/hello/signal.vala Normal file
View File

@ -0,0 +1,23 @@
public class MyButton : Object {
public signal void clicked ();
public void test () {
clicked (); // emit signal
}
}
void handler_c (MyButton source) {
stdout.printf ("handler C\n");
}
void main () {
var b = new MyButton ();
b.clicked.connect ((s) => stdout.printf ("handler A\n"));
b.clicked.connect ((s) => {
stdout.printf ("handler B\n");
});
b.clicked.connect (handler_c);
b.test ();
b.clicked.disconnect (handler_c);
}

View File

@ -50,7 +50,8 @@ public class TextFileViewer : Window
size_t size; size_t size;
FileUtils.get_contents( filename, out text, out size ); FileUtils.get_contents( filename, out text, out size );
this.text_view.buffer.set_text( text, (int) size ); this.text_view.buffer.set_text( text, (int) size );
} catch( Error e ) }
catch( Error e )
{ {
stderr.printf( "Ошибка: %s\n", e.message ); stderr.printf( "Ошибка: %s\n", e.message );
} }