Login | Register
My pages Projects Community openCollabNet

jtlscriptingengine
Project home

On Friday, May 18, the normal maintenance window (17:00 Pacific time) will be extended for data center maintenance until 23:00 Pacific. No extended down-time is planned, but brief delays and interruptions are possible throughout the period.

If you were registered and logged in, you could join this project.

Message from the owner(s)

This project is in a state where it is usable, but it still needs a bit of work. I will be actively working on it throughout the next couple months to polish it up and add the rest of the major features on the list.
Summary An embeddable scripting language written entirely in C#.
Category libraries
License Apache License
Owner(s) jegreenwo

Overview & History

I started the JTL scripting engine partially for fun, personal education, and also with the hope of using it in the MyGeneration code generator for template development. After I realized that I could embed the Microsoft Script Control into my code, I abandoned this project for a couple years. When I found the code on an old backup CD, I decided to finish it up and add a few features. Currently, the language is very similar to Javascript in syntax. The langauge can be embedded in a program by referencing the JTLInterpreter.dll assembly, or you can execute scripts through the command line using the JTL.exe executable assembly.

Mission

At the end of this initial development phase, I'd like to have a embeddable scripting engine written completely in C#. It will be customized for writing templates and reliably enable seamless interaction with CLR objects. I am also looking forward to experimenting with different programming syntax and constructs. Eventually I would like to tweak the performance, but performance is not my primary objective. I really wanted to do this from scratch using my own problem solving skills to figure out how to parse and interpret a custom scripting language.

Upcoming Features

  • User defined template tags (100% complete) - For example, you could define the tags to be "<%" and "%>" and the output stream operation to be "out.write", "file.write", or whatever function call you choose. The result would be a tagged template similar to an ASP or JSP page.
  • Eval (100% complete) - Evaluate dynamic code inline.
  • Static method support (100% complete) - Improve reflection object support to allow execution of static methods on .net classes.
  • Debugging Support - Add the ability to set breakpoints, add variable watches, etc. Implement Stop/Continue execution.
  • Simple Development Environment - Use the Scintilla.Net control to create a simple development environment for JTL. Build in execution/debugging support.
  • Command Tree Serialization - Serialize the command tree to an optimized stream for faster script loading and execution.
  • Save State - Save the current state of the script at a certain breakpoint so that it can be restarted at that point at a later time.
  • Commenting & Refactoring - Refactor the tokenizer and commandbuilder.

System Requirements

I've only tested this with the .net 2.0 framework on Windows XP. Eventually I will test this in Mono on a linux machine. I don't see any reason why that wouldn't work.

  • Windows
  • Microsoft.Net Framework 2.0

Sample Code

Here are a few samples of how to use jtl.

Execute script at runtime in your program.

...
ArrayList list = new ArrayList();
string myJtlCode = "myvar=12; ++myvar; items.Add(myvar);";

JTLEngine engine = new JTLEngine();
engine.AddObject("items", list);
engine.AddCode(myJtlCode);
engine.Execute();
...

Execute script from the command line.

C:\>jtl.exe .\testjtl.jtl

Some Sample JTL Code

// This defines type aliases for .net framework object types.
definetype ArrayList("mscorlib", "System.Collections.ArrayList");
definetype Process("system", "System.Diagnostics.Process");

// This launches a web browser to the project website.
process = new Process();
process.StartInfo.FileName = "http://jtlscriptingengine.tigris.org/";
process.Start();

// This shows how you can use .net collections in your script
mylist = new ArrayList();
mylist.Add("Test");
mylist.Add(12);

// standard for loop
for (j=0; j< 12; ++j) {}

// Goofy loop syntax I was playing with
max = 20
iterate from 0 to (max + 20) by 2 as idx
{
	//the idx variable contains the current index
}

// standard while loop
while (true)
{
	break;
}

// classes are very similar to javascript. You can define the class after the class invokation because classes are defined during tokenization.
tool = new StringTool();
aresult = tool.append("Welcome to ", "the revolution!");
mycount = aresult.length();

class NameValuePair(name, value) {
	this.name = name;
	this.value = value;
}

class StringTool() {
	this.append = stringAppend;
	this.nvpair = new NameValuePair("people", "suck");
	
}

function stringAppend(str1, str2) {
	return str1 + str2 + " (" + this.nvpair.name + ", " + this.nvpair.value + ") ";
}

A template based script.

!#TEMPLATE <~ ~> output.write
<~
class OutputObj() {
	this.data = "";
	this.write = output_write;
}

function output_write(str1) {
	this.data = this.data + str1;
}

output = new OutputObj();
~>This is a literal test... <~
output.write("some more text... ");
~>This is a sample literal
Here is some inline expressions: "<~= 12 + 20 ~>" Wahoo! 
<~
variableX = "X";

zzzzzzzz = output.data;
~>

Execute static methods on reflected types:

definetype Console("mscorlib", "System.Console");
world = "World!";
Console.WriteLine("Hello {0}", world);