oop.txt Basic Python-like OOP supportLINK


CONTENTS oop-contentsLINK

1. Intro oop-intro

2. Functionality provided oop-functionality

2.1. Features oop-features

2.2. Resources oop-resources

2.3. Built-in classes oop-classes

3. Class members oop-classinstance


1. Intro oop-introLINK

This plugin provides some basic OOP support with OOP model similar to Python.

Plugin requires frawor.


2. Functionality provided oop-functionalityLINK


2.1. Features oop-featuresLINK



pyoop.class : function (name, functions[, vars[, parents]])

+ unload

Defines a new class with given name, class functions (dictionary

{{fname}: {fref}}) and class variables (dictionary) (see

oop-__variables__ for how they then can be accessed). List {parents}

is used to inherit functions and variables, it must contain a number

of class names. Function will fail if class with requested name was

already defined in this plugin or in one of its dependencies.

Feature `pyoop' additionally contains three functions: `register' which will

add _classes variable to s: dictionary (it is frawor-fk-ignoredeps feature),

`load' which will populate _classes dictionary with classes defined by

dependencies of the plugin and `unload' which will remove defined classes when

plugin is unloaded.


To get an instance for particular class Foo you should use

let instance=s:_classes.Foo.new(arg1, arg2, ...)

This will pass variables arg1, arg2, ... to constructor (see oop-__init__).

Note that you must set self to class dictionary. In the above example it is

done by vim, if you want to use call() instead, use

let instance=call(s:_classes.Foo.new, [arg1, ...], s:_classes.Foo)


2.2. Resources oop-resourcesLINK


See frawor-f-addresource for information about how resource is obtained.

pyoop.instanceof :: name, instance -> Bool oop-r-pyoop.instanceofLINK

Returns true if {instance} is an instance of class {name}.


2.3. Built-in classes oop-classesLINK

Exception oop-class-ExceptionLINK

Basic class for custom exceptions. Functions:

warn oop-Exception.warnLINK

Generates error message using __str__ method and echoes it with

hl-ErrorMsg higlighting. Returns echoed error message. Note that

this warning will not be caught by :try ... :catch blocks.

raise oop-Exception.raiseLINK

Invokes oop-Exception.warn and then throws generated error message.

__str__ oop-Exception.__str__LINK

Returns basic error message. Should be redefined in child classes.


3. Class members oop-classinstanceLINK

When you request new class instance the following steps are performed.

1. New dictionary with keys __class__ and __variables__ is generated.

2. Generated dictionary is extended with parent classes variables (if any).

3. Generated dictionary is extended with its class variables (but before the

dictionary with varibles is generated by deepcopy(): one copy for every


4. Generated dictionary is extended with its class functions. Note that

functions from parent classes are inherited when class is registered.

5. Constructor is called with generated dictionary as a self dictionary.

6. Generated dictionary is returned.

All class members may have following special methods/variables:

__class__ oop-__class__LINK

Defined for all instances, contains class dictionary.

__variables__ oop-__variables__LINK

Defined for all instances, contains class variables. Unlike instance

variables, redefining variables in this dictionary will lead to

changing class variables default values (but not the values of already

existing class instances). Changing instance variables will affect

neither existing nor new class instances.

__init__({super}, ...) oop-__init__LINK

If defined, this method will be called whenever new instances are

generated. {super} argument is a dictionary with either a parent

class methods (if there is only one parent) or with {{name}:

{methods}} pairs. Other arguments are passed from oop-new.

vim: ft=help:tw=78