# class Defines a new object class
Usage
    class(<classname>[,<base_class_name>])
    {
        [internal] [function] <function_name>[([<parameter reminder>])]
        {
            <function body>
        }
        ...
    }
Description
Defines a new implementation of the class <classname>. If an implementation of that class was already existing it is removed with all the derived classes (and all the instances of this class and the derived ones are destroyed). <base_class_name> is the name of the class that the new class has to inherit from. If <base_class_name> is omitted, the new class inherits automatically from object. Note: The keywords "function" and "event" that were used in KVIrc versions previous to 3.0.0 have been removed since "useless". The function keyword, however, is still permitted. The keyword "internal" is useful when you want to hide certain function from the outside world. An internal function cannot be called by anyone else but the object instance itself. Note that this is different from the C++ "protected" or "private" keywords that refer to the object's class instead of the object instance. The <parameter reminder> part is an optional string that can be used to sign the parameters that the function expects; it acts as a programmer reminder or comment and it has no other meaning in KVIrc scripting. The <parameter reminder> respects the syntax of an expression, so it is terminated by a closed parenthesis. It's rather dangerous to use this command inside an object function handler: if the class definition <class> was already existing and it is a parent of the object's class, you might end up executing "inexisting" code. As a thumb rule, use this command only outside object function handlers. Only for the curious: implementing protected and private access list on members would have a considerable runtime overhead because of the strange nature of the KVS language. Object member calls are resolved completly at runtime (and that permits a lot of funny tricks like privateimpl) but unfortunately this also forces us to check access lists at runtime. Ok, this would be a relatively small footprint for the "private" keyword where we need to run UP the called object inheritance hierarchy but would have a significant performance footprint for the "protected" keyword where we would need to traverse the WHOLE inheritance tree of the called and calling objects... "internal" still allows hiding members in a lot of situations and is really fast to verify at runtime: no inheritance tree traversal is needed and only object pointers are compared.
Syntax Specification
    class(<classname:string>[,<base_class_name:string>])
    {
        [internal] [function] <function_name>[([<parameter reminder>])]
        {
            <function body>
        }
        ...
    }
Examples
        class(myclass,object)
        {
            constructor
            {
                echo Hey this is my constructor
                echo I have been just created
            }
            destructor
            {
                echo Ops...being destroyed
            }
            sayHello(this function expects no parameters)
            {
                echo Hello world!
            }
        }
See also
privateimpl, killclass, clearobjects, $classdefined(), objects documentation

Index, Commands

KVIrc 3.4.0 Documentation
Generated by root at Mon Dec 22 00:58:26 2008