diff --git a/classes.html b/classes.html index 2ffd2649..046c64f4 100644 --- a/classes.html +++ b/classes.html @@ -652,6 +652,111 @@ class Derived is Base { } +

Attributes #

+

experimental stage: subject to minor changes

+

A class and methods within a class can be tagged with ‘meta attributes’.

+

Like this:

+
+#hidden = true
+class Example {}
+
+ +

These attributes are metadata, they give you a way to annotate and store +any additional information about a class, which you can optionally access at runtime. +This information can also be used by external tools, to provide additional +hints and information from code to the tool.

+

+Since this feature has just been introduced, take note.

+

Currently there are no attributes with a built-in meaning. +Attributes are user-defined metadata. This may not remain +true as some may become well defined through convention or potentially +through use by Wren itself. +

+

Attributes are placed before a class or method definition, +and use the # hash/pound symbol.

+

They can be

+ +

An attribute key can only be a Name. This is the same type of name +as a method name, a class name or variable name, an identifier that matches +the Wren identifier rules. A name results in a String value at runtime.

+

An attribute value can be any of these literal values: Name, String, Bool, Num. +Values cannot contain expressions, just a value, there is no compile time +evaluation.

+

Groups can span multiple lines, methods have their own attributes, and duplicate +keys are valid.

+
+#key
+#key = value
+#group(
+  multiple,
+  lines = true,
+  lines = 0
+)
+class Example {
+  #test(skip = true, iterations = 32)
+  doStuff() {}
+}
+
+ +

Accessing attributes at runtime #

+

By default, attributes are compiled out and ignored.

+

For an attribute to be visible at runtime, mark it for runtime +access using an exclamation:

+
+#doc = "not runtime data"
+#!runtimeAccess = true
+#!maxIterations = 16
+
+ +

Attributes at runtime are stored on the class. You can access them via +YourClass.attributes. The attributes field on a class will +be null if a class has no attributes or if it’s attributes aren’t marked.

+

If the class contains class or method attributes, it will be an object with +two getters:

+ +

Attributes are stored by group in a regular Wren Map. +Keys that are not grouped, use null as the group key.

+

Values are stored in a list, since duplicate keys are allowed, multiple +values need to be stored. They’re stored in order of definition.

+

Method attributes are stored in a map by method signature, and each method +has it’s own attributes that match the above structure. The method signature +is prefixed by static or foreign static as needed.

+

Let’s see what that looks like:

+
+// Example.attributes.self = 
+// { 
+//   null: { "key":[null] }, 
+//   group: { "key":[value, 32, false] }
+// }
+
+#!key
+#ignored //compiled out
+#!group(key=value, key=32, key=false)
+class Example {
+  #!getter
+  getter {}
+
+  // { regular(_,_): { regular:[null] } }
+  #!regular
+  regular(arg0, arg1) {}
+
+  // { static other(): { isStatic:[true] } }
+  #!isStatic = true
+  static other()
+
+  // { foreign static example(): { isForeignStatic:[32] } }
+  #!isForeignStatic=32
+  foreign static example()
+}
+
+



Concurrency → ← Functions

diff --git a/values.html b/values.html index 750a9734..9aa3e151 100644 --- a/values.html +++ b/values.html @@ -162,11 +162,21 @@ again" "\%" // A percent sign. "\a" // Alarm beep. (Who uses this?) "\b" // Backspace. +"\e" // ESC character. "\f" // Formfeed. "\n" // Newline. "\r" // Carriage return. "\t" // Tab. "\v" // Vertical tab. + +"\x48" // Unencoded byte (2 hex digits) +"\u0041" // Unicode code point (4 hex digits) +"\U0001F64A" // Unicode code point (8 hex digits) + + +

A \x followed by two hex digits specifies a single unencoded byte:

+
+System.print("\x48\x69\x2e") //> Hi.
 

A \u followed by four hex digits can be used to specify a Unicode code point:

@@ -180,11 +190,6 @@ of the basic multilingual plane, like all-important emoji:

System.print("\U0001F64A\U0001F680") //> 🙊🚀 -

A \x followed by two hex digits specifies a single unencoded byte:

-
-System.print("\x48\x69\x2e") //> Hi.
-
-

Strings are instances of class String.

Interpolation #

String literals also allow interpolation. If you have a percent sign (%)