Emaker

From Erights

Revision as of 08:43, 23 April 2007 by Mscheffler (Talk)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

The E library package system is based on emakers. An emaker is an E source file named with ".emaker" as the suffix.

When an emaker is imported into an application, the code is executed at the time of import, and the result of that execution is returned to the importing program. Usually an emaker will return an object that can be used to create other objects - a maker (or factory).

There are several ways of making E aware of the availability of an emaker, corresponding to the several ways Java can become aware of a class. You can place it in a zip or a jar and place it in the jvm's ext directory. Or you can place it in a subfolder in the jvm's ext directory. Or you can place it, or a jar that contains it, on the classpath when you start up the jvm.

Emakers have an important security property: they come to life contained in a world with no authority. Such a world is even more restrictive than the Java sandbox used for applets. However, this world is more flexible than the sandbox because authority can be granted and revoked during operation using capabilities, as described in the [Walnut chapter on Secure Distributed Computing].


Simple Example

Place this in the java classpath of your E application (the classpath of the E interpreter is usually set in the E startup file "rune" or "rune.bat"). Name it "makeVector.emaker". For this example let's assume the position of the emaker relative to the classpath root is "/tests/makeVector.emaker"

def makeVector(var x, var y) {
    def Vector { 
        to getX() :any { return x }
        to getY() :any { return y }
        to setX(_x :float64) :void { x := _x }
        to setY(_y :float64) :void { y := _y }
    }
    return Vector
}

To use the emaker, you will have to import it.

? def makeVector := <import:tests.makeVector>
# value: <makeVector>

? def myVector := makeVector(2,4)
# value: <vector>

? myVector.getX()
# value: 2

? myVector.setX(8)
? myVector.getX()
# value: 8

See Also

E in a Walnut: Emakers

Personal tools
more tools