Functions | |
| muse_cell | fn_class (muse_env *env, void *context, muse_cell args) |
| (class name super-tree plist). | |
| muse_cell | fn_new (muse_env *env, void *context, muse_cell args) |
| (new supers plist). | |
| muse_cell | fn_obj_pty (muse_env *env, void *context, muse_cell args) |
| (-> obj pty [value]). | |
| muse_cell | fn_send (muse_env *env, void *context, muse_cell args) |
| (<- obj msg [args]). | |
| muse_cell | fn_send_super (muse_env *env, void *context, muse_cell args) |
| (<<- [class(es)] obj method-symbol arg1 arg2 etc). | |
(class name super-tree plist).
Syntax -
(class class-name-symbol
list-of-super-classes
class-property-list)
Returns a new class object - a symbol that has a certain set of properties that can be inherited by "derived" objects. muSE's class system is prototype based. A class is like an object prototype and the inheritance tree of an object actually traces which objects it is prototyped from. Almost the only difference between class and new is the syntax.
For example, here is a <size> class that has a width and height and can compute its area.
(class '<size> ; The symbol <size> is itself the class. () ; Empty super tree (width 320) ; Default width of 320 (height 240) ; Default height of 240 (area (fn (self) ; area method to compute the area of a size object. (* (-> self 'width) (-> self 'height)))))
The notion of a class in muSE is very dynamic. You can add properties and methods to classes after defining them, you can change the inheritance hierarchy of an object at run time, etc.
(new supers plist).
Syntax -
(new [super-class | list-of-super-classes] optional-property-list)
Creates a new object with the given properties overriding the class's properties. The list of super classes of an object is available as the object's super property. You can get this property using the expression -
(-> obj 'super)
For example, here is an instance of the <size> class -
(define pal-video-size (new '<size> '((width . 720) (height . 576))))
Now you can compute the number of pixels in a PAL video frame using the expression -
(<- pal-video-size 'area)
(<- obj msg [args]).
Syntax -
(<- obj message-symbol arg1 arg2 ...)
<- for fn_send is to imply the notion of sending a message to the object. "Sending a message" is the same as "invoking a method". A message handler is the looked up in the object's inheritance hierarchy and invoked with the object as the first argument, usually named self. The additional arguments are passed to the message handler function as is.
fn_send is technically equivalent to writing -
((-> obj message-symbol) obj arg1 arg2 ...)
(<<- [class(es)] obj method-symbol arg1 arg2 etc).
Use for invoking methods in specific super classes of an objecct instead of following the object's original inheritance hierarchy. This super class method invocation is normally for use within message handler functions and is technically equivalent to -
((-> super-class method-symbol) obj arg1 arg2 etc)
You can give a list of super-classes to search for the given method. This way, a message handler can surreptituosly change the inheritance hierarchy.
This function is really very liberal with what it accepts. It is not necessary for the given classes to be anywhere in the object's inheritance hierarchy, for example. So you can do delegation within a single method.
1.4.7