From 5c2a01cd8040574ef2714efe7307187e35113c0f Mon Sep 17 00:00:00 2001 From: Trevor Busk Date: Thu, 9 Oct 2025 13:44:43 -0400 Subject: [PATCH] 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