From 5c2a01cd8040574ef2714efe7307187e35113c0f Mon Sep 17 00:00:00 2001 From: Trevor Busk Date: Thu, 9 Oct 2025 13:44:43 -0400 Subject: [PATCH 1/2] feat: improve code attribute format and add additional info --- .../02-00-basics/02-08-code-attributes.md | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md b/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md index 646a6412..f3bdcc21 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md @@ -1,11 +1,48 @@ # 2.8. Code Attributes -Code attributes instruct the Vala compiler details about how the code is -supposed to work on the target platform. Their syntax is -`[AttributeName]` or -`[AttributeName(param1 = value1, param2 = value2, ...)]`. - -They are mostly used for bindings in *vapi* files, `[CCode(...)]` being -the most prominent attribute here. Another example is the `[DBus(...)]` -attribute for exporting remote interfaces via -[D-Bus](http://www.freedesktop.org/wiki/Software/dbus). +Code attributes instruct the Vala compiler details about how the code is supposed to work on the target platform. +They are mostly used for bindings in *vapi* files. + +The most prominent example is the `[CCode (...)]` attribute: + +```vala +[CCode (cname = "SDL_PropertiesID", has_type_id = false)] +public struct PropertiesID : uint32 {} +``` + +Another common example is the `[DBus (...)]` attribute, which is used for exporting remote interfaces via +[D-Bus](http://www.freedesktop.org/wiki/Software/dbus): + +```vala +[DBus (name = "net.example")] +public interface Header.Example { + // ... +} +``` + +Here are some examples of the syntax: + +```vala +[AttributeName] +class Example { + // ... +} + +[AttributeName, AnotherAttributeName] +var number = 1; + +[AttributeName, AnotherAttributeName (name = "value"), YetAnotherAttributeName] +var str = "string"; + +[AttributeName (name = "value"), AnotherAttributeName] +var character = 'c'; + +[AttributeName] +[AttributeName (name = "value")] +var boolean = true; + +[AttributeName (name = "value", anotherName = 1, thirdName = false)] +int integer = 1; +``` + +You can use as many attributes and arguments in the attributes as you want. \ No newline at end of file From 8bb83e4216637e756c694c75d0496556a49408d0 Mon Sep 17 00:00:00 2001 From: Tbusk Date: Sun, 9 Nov 2025 14:43:11 -0500 Subject: [PATCH 2/2] change: adding reference manual link as requested --- .../main/02-00-basics/02-08-code-attributes.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md b/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md index f3bdcc21..6cbbe03f 100644 --- a/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md +++ b/docs/tutorials/programming-language/main/02-00-basics/02-08-code-attributes.md @@ -45,4 +45,6 @@ var boolean = true; int integer = 1; ``` -You can use as many attributes and arguments in the attributes as you want. \ No newline at end of file +You can use as many attributes and arguments in the attributes as you want. + +For more information on attributes, refer to the [reference manual](https://gnome.pages.gitlab.gnome.org/vala/manual/attributes.html). \ No newline at end of file