Hi Mateusz.
Regarding the annotations - I seem to have lost my notes from the meetup, and have some questions: I've managed to play around the @Implements annotation and it seems to work alright.
Can you remind me what does the @constant annotation do?
@constant is a "fake" annotation that sets the PROGRAM_CONSTANT flag on the class it is contained in. This flag indicates that creating instances of the class is valid in constant expressions (like eg in an annotation expression).
I've tried running the annotations() buitin and pass both classes and class instances to it, but both ways the returned array is always empty.
You probably only have annotations on the class itself, and not any on its members.
Note that annotations() works analogously to indices(), values() and types().
To see annotations on a class (or inherit) you currently need to have at least on non-protected member of the class, and specify the recurse flag to annotations().
Is it already possible to define your own annotations in Pike code? If yes, how to do it? Some examples would be great.
You may want to take a look at the annotation tests in src/testsuite.in. An example adapted from the testsuite:
local class InheritedImplements { // Extend the default Implements annotation. inherit Pike.Annotations.Implements;
// Make it valid to clone this class in a constant expression context. @constant;
// Make this attribute inherited. @Pike.Annotations.Inherited; }
class A { // Everything that inherits A must implement A. @InheritedImplements(A); int foo() {} }
class B { inherit A; int foo() { return 1; } }
class C { inherit A; // This fails due to bad return type compared with A::foo(). float foo() { return 1.0; } }
Thanks in advance.
/grubba
pike-devel@lists.lysator.liu.se