Plugins - Cinderella Documentation
Description: The user's guide to the Interactive Geometry Software Cinderella

Skip to content

# Plugins

With CindyScript it is possible to enhance and customize the behavior of Cinderella in an almost unlimited variety of ways. Still it may be desirable from time to time to be able to use self-written Java code in connection with Cinderella. The Cinderella Plugin Structure gives a way to handle such situations. There may be several reasons that make it desirable to use a plugin. Here are some of them

- Performance: For some tasks CindyScript may simply be too slow, so that one wants to use some custom optimized code.

- Native libraries: Sometimes one wants to use native libraries (like for instance the JOGL library for dealing with 3D graphics). In these cases a plugin may be used to link Cinderella to this library.

- Licensing issues: Plugins make it possible to write and to offer extensions for Cinderella that run under a specifically chosen license (for instance GNU GPL). We will make use of this ourselves in the future and publish open source extensions to Cinderella. These plugins will be available for download soon under....

- Third-party code: Plugins also form a good basis to include Java code written by others into a Cinderella project.

At the time of this writing, Plugins are only available in the standalone version of Cinderella and are not applicable in applets. This will be fixed in the near future.

### Plugin Architecture

For detailed descriptions of the plugin architecture see our website at http://cinderella.de/plugins. There you may also find example plugins as well as suitable make files to create them. Here we only describe the workflow very roughly.

A plugin itself is a `.jar` file that contains executable Java classes. The core link of the plugin is a Java file (compiled to a class file) that exports all the functionality of the plugin to Cinderella. Within Cinderella, the plugin can be accessed using CindyScript. The core file of the plugin must extend the Java class `CindyScriptPlugin`. This parent class is available through the `cindy2.jar` file in the Cinderella application.

The code for a plugin may typically look as follows:

    import de.cinderella.api.cs.CindyScript;
    import de.cinderella.api.cs.CindyScriptPlugin;
    import java.awt.*;
    import java.util.ArrayList;
    import java.util.Arrays;

    public class ExamplePlugin extends CindyScriptPlugin {

    }

The fragments given by code like `@CindyScript("square")` declare the name under which the function is accessible in CindyScript. The plugin can be used in CindyScript after it has been loaded with the `use` function:

#### Loading a plugin: `use(<string>)`

Description: This function loads a plugin with the name given as argument. It is good practice to call this function in the initialization slot of CindyScript.

So the above plugin may be used within CindyScript as follows:

    use("ExamplePlugin");
    println(sayHello());
    println(square(4));
    println(grayvalue((0.7,0.4,0.1)));
    println(testarray([1,2,3,4,5]));

This will create the output

    Hello from plugin
    16
    102.3333
    [1.0, 2.0, 3.0, 4.0, 5.0]

Observe that all class casts are performed automatically. For a detailed description of the casting rules see the online documentation.