Object
Every object in a running program, including objects your program defines via "object" and "class" definitions and instances of intrinsic classes, ultimately derives from the intrinsic class Object.
You can never instantiate Object directly, since this is an "abstract" class. However, since every object is a subclass of Object, every object in the system inherits the methods defined by Object.
Object methods
The Object class defines a number of methods. Since all objects are subclasses of Object, all objects inherit these methods. Most of these methods are related to the the relationships between objects and classes.
The adv3Lite library defines a nyumber of additional methods on the Object class. Although these sre not strictly part of the intrinsic Object class they are included here for the convenience of adv3Lite users, and marked [a3L].
callInherited(cl, prop, [args])[a3L]
inherited cl.prop
would from within a method, but allows
you to do this from an arbitrary point outside of the object's
own code. I.e., you can say obj.callInherited(cl, &prop)
and
get the effect that inherited c.prop
would have had from within
an obj
method.
cf(func) [a3L]
"<<(cf{: myProp = nil })>>"
.
checkDisplay(prop)[a3L]
createIterator() [a3L]
createLiveIterator() [a3L]
foreach
to be used with an
arbitrary object, iterating once over the loop with the object
value)
This is one
of several methoda added to Object to allow methods intended for
collections to work on singleton objects.
display(prop)[a3L]
displayAlt(prop, altMsg?)[a3L]
true
if anything is
displayed. Otherwise, if the altMsg parameter is supplied (either as a single-quoted string
or as a property pointer) displays that instead, and then in any case return nil
to tell the
caller that nothing was displayed by prop.
This method is primarily for use with properties such as smellDesc
and
listenDesc
on Thing
for which alternatives may need to be displayed if the properties don't display anything, but custom
classes and objects created by game authors may wish to use it for their own purposes.
forEach(func) [a3L]
getSuperclassList()
For example, consider these definitions:
class A: object; class B: object; class C: B; myObj: C, A;
The result of myObj.getSuperclassList() will be the list [C, A]. Note that class B is not included in the list, because it is not a direct superclass of myObj, but is a superclass only indirectly through class C.
getPropList()
getPropParams(prop)
- [1] is the minimum number of arguments taken by the method;
- [2] is the number of additional optional arguments taken by the method;
- [3] is true if the method accepts any number of additional arguments, nil if not.
The second element gives the number of optional arguments; only intrinsic methods will ever yield a non-zero value for this element, because regular methods cannot specify optional arguments. For example, the substring() method of the String intrinsic class can take either one or two arguments, so its return list is [1, 1, nil], indicating that the function takes a minimum of one argument, can take one additional optional argument, but does not take an unlimited varying argument list after those arguments.
If the third element is true, it indicates that the method was defined with the "..." varying argument list notation.
If the specified property is not defined for the object, the method returns [0, 0, nil], because it's valid to invoke the property with no arguments in this case.
isClass()
isTransient()
ofKind(cls)
mapAll(func<() [a3L]
propDefined(prop, flags?)
- PropDefAny - the function returns true if the object defines or inherits the property.
- PropDefDirectly - the function returns true only if the object directly defines the property; if it inherits the property from a superclass, the function returns nil.
- PropDefInherits - the function returns true only if the object inherits the property from a superclass; if it defines the property directly, or doesn't define or inherit the property at all, the function returns nil.
- PropDefGetClass - the function returns the superclass object from which the property is inherited, or this object if the object defines the property directly. If the object doesn't define or inherit the property, the function returns nil.
propInherited(prop, origTargetObj, definingObj, flags?)
The return value depends on the value of the flags argument:
- PropDefAny - the function returns true if the object inherits the property, nil otherwise.
- PropDefGetClass - the function returns the class object from which the property is inherited, or nil if the property is not inherited.
This method is most useful for determining if the currently active method will invoke an inherited version of the method if it uses the inherited operator; this is done by passing targetprop for the prop parameter, targetobj for the origTargetObj parameter, and definingobj for the definingObj parameter. When a class is designed as a "mix in" (which means that the class is designed to be used with multiple inheritance as one of several base classes, and adds some isolated functionality that is "mixed" with the functionality of the other base classes), it sometimes useful to be able to check to see if the method is inherited from any other base classes involved in multiple inheritance. This method allows the caller to determine exactly what inherited will do.
Note that the inheritance order is deterministic (i.e., it will always be the same for a given situation), and that it depends on the full class tree of the original target object. For example, suppose we have a set of class definitions like this:
class A: object x() { "A.x\n"; inherited(); } class B: object x() { "B.x\n"; inherited(); } class C: B, A x() { "C.x\n"; inherited(); }
Now suppose we run some code like so:
new B().x(); new C().x();
The first line will simply display "B.x". B inherits directly from TadsObject, so when B.x() calls inherited(), it will find no definition of x() in any base class (since TadsObject doesn't define it), so inherited() will do nothing.
The second line, however, will display this:
C.x B.x A.x
So, even though the call to inherited() in B.x() went straight to TadsObject when B.x() was invoked from the first line above, the same call to inherited() in B.x() proceeds to A.x() when invoked from the second line above. The difference is that C inherits from both B and A. B is the first superclass, so the call to inherited() in C.x() proceeds to B.x(). But C also inherits from A, and the superclass order is defined so that A comes after B in C's superclass list. So, the call to inherited() in B.x() proceeds to A.x() this time, since that's the next superclass in inheritance order for the original target object.
propType(prop)