I have written the following (very simple) ring buffer class, which should allow array access via the @:arrayAccess macro:
class RingBuffer<T>
{
private var _elements : Array<T> = null;
public function new(p_numElements : Int, p_defaultValue : T)
{
_elements = new Array<T>();
for (i in 0 ... p_numElements)
{
_elements.push(p_defaultValue);
}
}
public function add(p_value : T) : Void
{
// Remove the first element
_elements.splice(0, 1);
_elements.push(p_value);
}
@:arrayAccess public inline function get(p_index : Int)
{
retu _elements[p_index];
}
@:arrayAccess public inline function set(p_index : Int, p_value : T)
{
_elements[p_index] = p_value;
retu p_value;
}
}
But when I try to use array access on an instance of the class, I get an error telling me "Array access is not allowed on...".
Did I do something wrong in using the macro? I was basically following the example in the manual.
