diff options
author | Milo Gilad <milogaccnts@gmail.com> | 2017-08-25 10:11:24 -0400 |
---|---|---|
committer | Milo Gilad <milogaccnts@gmail.com> | 2017-08-25 10:11:24 -0400 |
commit | 1abae4b25de43e05df3ba225986997bc72eb3f8a (patch) | |
tree | 5e6a74026063393788aa61db4561222ea2175b47 /vala.html.markdown | |
parent | 0510b181f0987b516402e63270b062bdecd360f2 (diff) |
Added namespaces, structs, began classes and OOP, and removed Reference Types.
Diffstat (limited to 'vala.html.markdown')
-rwxr-xr-x | vala.html.markdown | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/vala.html.markdown b/vala.html.markdown index 73ffa55c..036e873d 100755 --- a/vala.html.markdown +++ b/vala.html.markdown @@ -141,20 +141,7 @@ switch (a) { break; } // switch statement -/* Reference Types */ - -// Reference types are classes. - -class Message : GLib.Object { // Class Message extends GLib's Object - public string sender; // a public field - public string text {get; set;} // a public property - private bool sent = false; // private field - public void send(string message_sender) { // public method - sender = message_sender; - sent = true; - } - -} +/* Type Casting and Inference */ int cast_to_float = 10; float casted_float = (float) cast_to_float; // static casting; no runtime checks @@ -217,11 +204,54 @@ void final_delegate_demo() { (a) => { stdout.printf("%d\n", a); } // Prints "a" +/* Namespaces */ + +namespace NamespaceDemo { + // Allows you to organize variable names + int namespace_int = 12; +} +namespace_int += 5; // Won't compile + +using NamespaceDemo; +namespace_int += 5; // Valid + +/* Structs */ + struct Closet { - public uint shirts; + public uint shirts; // Default access modifier is private public uint jackets; } +Closet struct_init_1 = Closet(); // or Closet struct_init_1 = {}; +Closet struct_init_2 = {15, 3}; +var struct_init_3 = Closet() { // Type inference also works + shirts = 15; + jackets = 3; +} + +/* Classes and Object-Oriented Programming */ + +class Message : GLib.Object { // Class Message extends GLib's Object + private string sender; // a private field + public string text {get; set;} // a public property + internal bool sent = false; // internal (classes in same package) field + + public void send(string message_sender) { // public method + sender = message_sender; + sent = true; + } + + public Message() { // Constructor + // ... + } + +} + +interface InterfaceDemo { // Can be used as a mixin + // ... +} + + enum HouseSize { SMALL, MODERATE, |