Skip to content

Commit 4afc624

Browse files
authored
feat: improve code attribute format and add additional info (#113)
* feat: improve code attribute format and add additional info * change: adding reference manual link as requested
1 parent d3ba06e commit 4afc624

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed
Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
11
# 2.8. Code Attributes
22

3-
Code attributes instruct the Vala compiler details about how the code is
4-
supposed to work on the target platform. Their syntax is
5-
`[AttributeName]` or
6-
`[AttributeName(param1 = value1, param2 = value2, ...)]`.
7-
8-
They are mostly used for bindings in *vapi* files, `[CCode(...)]` being
9-
the most prominent attribute here. Another example is the `[DBus(...)]`
10-
attribute for exporting remote interfaces via
11-
[D-Bus](http://www.freedesktop.org/wiki/Software/dbus).
3+
Code attributes instruct the Vala compiler details about how the code is supposed to work on the target platform.
4+
They are mostly used for bindings in *vapi* files.
5+
6+
The most prominent example is the `[CCode (...)]` attribute:
7+
8+
```vala
9+
[CCode (cname = "SDL_PropertiesID", has_type_id = false)]
10+
public struct PropertiesID : uint32 {}
11+
```
12+
13+
Another common example is the `[DBus (...)]` attribute, which is used for exporting remote interfaces via
14+
[D-Bus](http://www.freedesktop.org/wiki/Software/dbus):
15+
16+
```vala
17+
[DBus (name = "net.example")]
18+
public interface Header.Example {
19+
// ...
20+
}
21+
```
22+
23+
Here are some examples of the syntax:
24+
25+
```vala
26+
[AttributeName]
27+
class Example {
28+
// ...
29+
}
30+
31+
[AttributeName, AnotherAttributeName]
32+
var number = 1;
33+
34+
[AttributeName, AnotherAttributeName (name = "value"), YetAnotherAttributeName]
35+
var str = "string";
36+
37+
[AttributeName (name = "value"), AnotherAttributeName]
38+
var character = 'c';
39+
40+
[AttributeName]
41+
[AttributeName (name = "value")]
42+
var boolean = true;
43+
44+
[AttributeName (name = "value", anotherName = 1, thirdName = false)]
45+
int integer = 1;
46+
```
47+
48+
You can use as many attributes and arguments in the attributes as you want.
49+
50+
For more information on attributes, refer to the [reference manual](https://gnome.pages.gitlab.gnome.org/vala/manual/attributes.html).

0 commit comments

Comments
 (0)