如是,你比较喜欢C#的语法,但又但心它的效率,那么vala是个不错的选择。
http://live.gnome.org/Vala
在mojo的源有vala的包,但版本较老,这里编译了一个目前的最新版0.7.4版,下载:vala-0.7.4.deb
控制台应用示例: main.vala
Gtk应用示例:gtk-hello.vala
http://live.gnome.org/Vala
在mojo的源有vala的包,但版本较老,这里编译了一个目前的最新版0.7.4版,下载:vala-0.7.4.deb
控制台应用示例: main.vala
using GLib;
public class HelloVala: GLib.Object
{
public static int main (string[] args)
{
stdout.printf ("Hello world!\n");
return 0;
}
}
编译命令:public class HelloVala: GLib.Object
{
public static int main (string[] args)
{
stdout.printf ("Hello world!\n");
return 0;
}
}
valac -o main main.vala
./main
./main
Gtk应用示例:gtk-hello.vala
using Gtk;
static int main (string[] args)
{
Gtk.init (ref args);
var window = new Window (WindowType.TOPLEVEL);
window.title = "First GTK+ Program";
window.set_default_size (300, 50);
window.position = WindowPosition.CENTER;
window.destroy += Gtk.main_quit;
var button = new Button.with_label ("Click me!");
button.clicked += (source) =>
{
source.label = "Thank you";
};
window.add (button);
window.show_all ();
Gtk.main ();
return 0;
}
编译命令:static int main (string[] args)
{
Gtk.init (ref args);
var window = new Window (WindowType.TOPLEVEL);
window.title = "First GTK+ Program";
window.set_default_size (300, 50);
window.position = WindowPosition.CENTER;
window.destroy += Gtk.main_quit;
var button = new Button.with_label ("Click me!");
button.clicked += (source) =>
{
source.label = "Thank you";
};
window.add (button);
window.show_all ();
Gtk.main ();
return 0;
}
valac --pkg gtk+-2.0 gtk-hello.vala
./gtk-hello
运行效果:./gtk-hello