Home   Info   DevZone   Wiki  
UsersWeb  |  MainWeb  |  InfoWeb  |  DevZoneWeb  |  SupportWeb
GenericScriptingInterface ] [ not logged in ] [ Web: Imported ] goto:  options
[ get info on or edit ] login or new user ] [ list of topics, hubs & nodes, or recent changes ]

GSI - The Generic Scripting Interface


NOBREAK SIZE="1"> The GSI is a generic way to encapsulate any scripting language in Java and allow communication between the two via a simple interface.

Basic API

ScriptLoader (abstract)
Similiar to class loader, it loads a script (text or binary) into a script object. There is one per scripting language (like LuaScriptLoader).

Script (abstract)
Encapsulates the script, starts interpretations via the abstract void execute() throws ScriptException;.

Script.Element (abstract inner)
Represents an element of a script in a generic way, can be a function, global value or a class depending on the scripting language.

Scriptable (interface)
Says a class can be linked to a script, one method public ScriptInfo getScriptInfo();.

ScriptInfo
Similiar to BeanInfo, encaps methods and variables that can be accesed by a Script

ScriptException
The super for all Script related exceptions (NoScriptFoundException, ScriptInterpeterationException, et al.).

Script as Application:

One of the applications of GSI is a simple application that can run most any script (assuming its valid and can run solo (that is doesnt need an application to communicate with)) as an application:

<CODE>

package org.jos.apps;

import org.jos.gsi.*;

public class ScriptRunner {
 private Script script;
 
 public static void main(String args[]) {
  ScriptRunner runner;
  if(args.length < 1) {
	System.out.println("You must specify a script file in the command arguments.");
	System.exit(1);
  }
  runner = new ScriptRunner(args[0]); //or is that args[1], I can never remember
  runner.start();
  System.exit(0);
 }

 public ScriptRunner(String scriptToRun) {
  try {
	script = ScriptLoader.load(scriptToRun)
  } catch(ScriptException e) {
	System.out.println(e);
  }
 }

 public void start() {
  try {
	script.execute();
  } catch(ScriptException e) {
	System.out.println(e);
  }
 }
}

This app has no idea what script or even what language its running.

--DigiGod 99.08.01


Content of these pages are owned and copyrighted by the poster.
Hosted by: