Member operations
This section contains definitions of functions that can be used to read or write members. Several different methods of accessing members are available, the main differentiating factor being efficiency. Specifying the member name as C strings is simple, but it is also the slowest method. Numeric member ids are a faster way of accessing members, with some additional complexity. Direct member access using a slot index is fastest, but its use is severely limited to a specific set of circumstances.
See also: Calling methods is described in section Call operations.
Accessing public members
- AValue AMember(AThread *t, AValue object, const char *member)
- Return the value of a public member of an object (or AError). This is equivalent to using the dot operator.
- AValue ASetMember(AThread *t, AValue object, const char *member, AValue mv)
- Set the value of the specified public member of an object to value mv. This is equivalent to using the dot operator on the left-hand-side of an assignment statement. The return value is ANil, if successful, or AError.
- AValue ASuperMember(AThread *t, AValue *frame, const char *member)
- Return the value of the specified public member based on the definition
in the
superclass. This is equivalent to using super.member in Alore
code. This
function should only be called while executing a method, and the frame
argument must point to the frame of the method.
If member refers to a method, a bound method is returned that can be passed to ACallValue to call the method. Here is an example:
AValue ExampleMethod(AThread *t, AValue *frame) { /* Get a bound method object that is bound to the method myMethod defined in the superclass and the self object. */ AValue s = ASuperMember(t, frame, "myMethod"); if (AIsError(s)) return AError; /* Call the method myMethod defined in the superclass. /* return ACallValue(t, s, 0, frame + 1); }
- AValue ASetSuperMember(AThread *t, AValue *frame, const char *member, AValue mv)
- Set the value of the specified public member of an object to value mv,
using the setter defined in the superclass. This is
equivalent to performing an assignment using the super keyword:
super.member = mv
The return value is ANil, if successful, or AError.
- int AMemberNum(AThread *t, const char *member)
- Return a numeric id of a member. This id can be used instead of the name of the member to refer to the member in some contexts.
- AValue AMemberByNum(AThread *t, AValue object, int member)
- Return the value of a public member of an object. This is equivalent to using the dot operator. The member is specified using a numeric id obtained using AMemberNum.
- AValue ASetMemberByNum(AThread *t, AValue object, int member, AValue mv)
- Set the value of the specified public member of an object to value mv. This is equivalent to using the dot operator on left-hand-side of an assignment statement. The member is specified using a numeric id obtained using AMemberNum.
- ABool AHasMemberByNum(AValue object, int member)
- Return a boolean indicating whether an object has the specified public member defined or inherited. The member is specified using a numeric id obtained using AMemberNum.
Direct member access
Note: Direct member access is possible only in some specific contexts. Direct member access is most commonly used for accessing private member variables, direct member access being the only supported way of accessing them. See the links below for details.
- AValue AMemberDirect(AValue object, int num)
- Return the value of a member. The member is specified using a numeric slot index num. See Accessing member variable slots directly for more information. This operation never raises an exception and performs no error checking.
- void ASetMemberDirect(AThread *t, AValue object, int num, AValue mv)
- Set the value of a member. The member is specified using a numeric slot index num. See Accessing member variable slots directly for more information. Raise a direct exception on all error conditions.