Native .NET constructs

Coden gives developers the freedom of semantics they choose to write their plugins. It uses native .NET language constructs such as classes and methods to define what a plug-in does. There are no special steps involved and no interfaces or classes to be derived from. Indeed, you can take already existing non-Coden assemblies and make them into plugins.

Many ways to write a plug-in

A Coden plug-in conceptually boils down to an "operator" that takes a number of inputs, does something, and then produces an output. Programming-wise the closest definition to this is a function, however, classes and other methods can have their benefits for defining plugins.

As an example we will be looking at a plug-in that generates a mesh based on some parameters. Following are all the different methods for defining such a plug-in.

1. As a function

The simplest way to define a plug-in is through a static function:

public static PolygonMesh3 Cube( float width, float length, float height )
{
	var result = new PolygonMesh3();
 
	// Edit result's vertex and face list to define a 3d cube...
 
	return result;
}

Our function takes three inputs (width, length, and height) and produces a PolygonMesh3 object as a result. Coden will look at this function, see that its output is a PolygonMesh3 and automatically assume and use it as a mesh generator plug-in.

NOTE: The function must be static and be defined inside a static class that is marked as pluggable (unless the whole assembly is marked as pluggable).

2. As a derived class

public class Cube : PolygonMesh3
{
	public void ValidateClass()
	{
		// Edit this class' vertex and face list to define a 3d cube...
	}
 
	public float width, length, height;
}

Our Cube class is derived from PolygonMesh3 so, in essence, it represents an instance of our plug-in. This can have a number of benefits over using the previous example of function approach. For example, you can store persistent parameters or cache in your class that can be reused between evaluations.

ValidateClass() function is called whenever our cube needs to be regenerated, usually after parameter changes.

3. As a class constructor

public class Cube : PolygonMesh3
{
	public Cube( float width, float length, float height )
	{
		// Edit this class' vertex and face list to define a 3d cube...
	}
}

Class constructors can also be used for defining a plug-in. Whenever an instance of our cube mesh is requested the parameters will be passed into the constructor of our class and we can generate the mesh there.

4. As a class function

public class Cube
{
	public PolygonMesh3 Generate( float additionalParameter )
	{
		var result = new PolygonMesh3();
 
		// Edit this class' vertex and face list to define a 3d cube...
 
		return result;
	}
 
	public float width, length, height;
}

In addition to all of the above methods we may also define a plug-in as a member function of a class. In the above example, our plug-in will be called Generate and it will take four parameters (width, length, height, additionalParameter). Note how additionalParameter is appended to the end of class' parameters. This provides all benefits of defining a plug-in as a class plus the simplicity of defining a function.