hScript

24.07.2008 3546 1

This was made with Haxe and the important code, here, is :

function parseScript( s : String )
{
	var parser = new hscript.Parser();
	var program = parser.parseString( s );
	var interp = new hscript.Interp();
	interp.variables.set( "root", flash.Lib.current );
	interp.variables.set( "new", createInstance );
	interp.variables.set( "class", getClass );
	interp.execute( program );
}
	
function createInstance( s : String, a : Array<Dynamic> )
{
	return Type.createInstance( Type.resolveClass( s ), a );
}
function getClass( s : String )
{
	return Type.resolveClass( s );
}

"root" variable is "shared" with the interpreter and set to flash.Lib.current.
Since there is no "new" keyword in hScript, in order to simulate a constructor, we can call a method that uses Type.createInstance. Here this method is named "new" and is still shared with the interpreter.
If you want to access a static field of a class, you have to use "class" function that is shared with the interpreter and returns the real class from a string.
With this sample, you can access all the flash player's API basically. If you want to access a specific class you must first import it. In other words, you can access all the classes built into the SWF or available by the flash player.
Check http://code.google.com/p/hscript/ to see more informations.

Commentaires

14.08.2010 à 15:23 Twoja

Moi aussi je t'aime fort Moj Misiu !!!

Laisser un commentaire

http://
×