Hosted by Three Crickets

Scalable Alternative to JSR-223

Scripturian logo: kitten in shawl


Next chapter: Text-with-scriptlets Documents
Or, go back to the manual's table of contents

Part 4: Entering Executables

In the previous examples, our executable were "plainly" executed, meaning that execution started at the natural starting point of the executable. Such an executable is often referred to as a "script," meaning that it is a series of commands. However, most programming languages also support more sophisticated "entry points": these are called "functions," "methods," "closures," "blocks," etc. in different languages. "Entering" in Scripturian is an abstraction over "invoking," "calling," "sending a message to," etc. in reference to such an "entry point."

Making an Executable Enterable

Entering an executable requires you first to execute it in a special way. Instead of calling "execute()", we'll call "makeEnterable()":

ExecutionContext executionContext = new ExecutionContext();
boolean enterable = false;
	enterable = executable.makeEnterable( "mykey", executionContext );
	if( enterable )
		this.executable = executable;
	if( !enterable )

Why do we need a different from that of plain execution?

The first difference is that the executable needs to prepare the entry points for us to enter: it needs to define the functions, link the closures to variables, etc. And so, "makeEnterable()" does in fact execute the executable "plainly."

The second difference is that these entry points are stored in the execution context, and so we cannot simply release it. (It's actually more complicated: depending on the programming language and how it handles scope, these entry points might in fact be capturing the scope that was available during their closure.) So, what happens is that if "makeEnterable()" returns true, the execution context is considered to be "consumed" by the executable. To release it, we will need to call "release()" on the executable itself when we no longer need to keep it alive for the purpose of entering.

(In fact, you will not be able to release a consumed execution context even if you tried. Once consumed, it is immutable, and will throw an exception on any attempt to modify it.)

The third requirement explains the "mykey" enterable key used. This is used internally by Scripturian to identify which execution context to use when entering. This would be an issue if there is a you would be calling "makeEnterable()" at other places in your application on the same executabe. Enterable keys provide a powerful feature which, again, allows for scalability: the very same executable can be reused at various parts of your application without each part knowing about the others, as long as they use separate keys.

Note that these keys are unrelated to threads: any number of threads can use the same key. However, if they do, they will be using the same execution context: the same standard out, services, scope, etc.

Entering an Executable

Now that our executable has been made enterable, we can very easily enter it, by specifying the enterable key, then the entry point name, and finally any arguments to send to the entry point:

this.executable.enter( "mykey", "sayHello", 3, "Tal" );

Here is the JavaScript source code:

function sayHello(count, name) {
	for (var i = 0; i < count; i++) {
		log.write(name + '\n');

There are a few points to note:

Next chapter: Text-with-scriptlets Documents
Or, go back to the manual's table of contents