Hscript addon featuring script classes, imports, usings, properties, string interpolation and more.
- Package
- Import
- Using
- Property
- String interpolation
- Script Class
- Abstracts in script
- Key => value iterator
??and??=operators- Rest
packagescripts.hello.world;importhaxe.ds.StringMap;
varmap=newStringMap();
map.set("Hello","World");
trace(map.get("Hello")); // WorldSupports both the as and in aliases.
importhaxe.ds.StringMapasStrMap;
varmap=newStrMap();
map.set("Hello","World");
trace(map.get("Hello")); // Worldimporthaxe.ds.StringMapinStrMap;
varmap=newStrMap();
map.set("Hello","World");
trace(map.get("Hello")); // WorldimportReflect.getProperty;
vara= {
"hello":"world"
};
returngetProperty(a,"hello");usingReflect;
vara= {
"Hello":"World"
};
trace(a.getProperty("Hello")); // Worldvar_a='Hello World';
vara(get,set):String;
functionget_a():Stringreturn_a;
functionset_a(v:String):Stringreturn_a=v;
trace(a); // Hello Worldvara='Hello';
trace('RuleScript: $a World'); // RuleScript: Hello Worldvara= {
a:'RuleScript',
b: () ->'Hello',
c: (a) ->a?'World':'';
};
trace('${a.a}: ${a.b() +''+a.c(true)}'); // RuleScript: Hello WorldRuleScript supports scripted classes; these can have strict and non-strict constructors.
Script :
classScriptedClassextendstest.ScriptedClassTest
{
publicfunctionnew(customArg:Int,arg1:String)
{
trace('Constructor.pre: $customArg, $arg1');
super('Super Arg');
trace('Constructor.post: $customArg, $arg1'); }
overridepublicfunctioninfo()
{
return'Scripted class, super info: ${super.info()}';
}
}Source :
classScriptedClassTestimplementsRuleScriptedClassextendsSrcClass {}See Main.hx, ScriptedClassTest.hx, ScriptedClass.
RuleScriptAbstracts.txt in any classpath :
test.HelloWorldAbstract
test/HelloWorldAbstract.hx :
abstractHelloWorldAbstract(String) fromStringtoString
{
publicstaticfunctionrulescriptPrint():HelloWorldAbstractreturn'Hello World';
}Script :
importtest.HelloWorldAbstract;
trace(HelloWorldAbstract.rulescriptPrint()); // Hello WorldMore templates can be found in test/src/Main.hx.
varmap= [
'RuleScript'=>'Hello World',
];
for(key=>valueinmap){
trace('$key: $value'); // RuleScript: Hello World
}trace(null??'Hello World'); // Hello Worldvara='hello';
a??='world';
trace(a); // helloa=null;
a??='world';
trace(a) // worldvarf=function(hello:String, ...rest:Dynamic)
{
return'$hello: '+rest.join('');
}
trace(f('Rulescript','Hello','World','!')); // Rulescript: Hello World !trace(f('Rulescript',...['Hello','World','!'])); // Rulescript: Hello World !- Script
usingcallbacks support a maximum of 8 arguments. - Wildcard imports are not supported.
- AbstractMacro only supports
staticabstract fields.
- Improve hscript module parser
Installing the library:
haxelib version
- Haxelib :
haxelib install rulescript - Hmm :
hmm haxelib rulescript
- Haxelib :
github version
- Haxelib :
haxelib git rulescript https://github.com/Kriptel/RuleScript.git - Hmm :
hmm git rulescript https://github.com/Kriptel/RuleScript.git
- Haxelib :
github version (dev)
- Haxelib :
haxelib git rulescript https://github.com/Kriptel/RuleScript.git dev - Hmm :
hmm git rulescript https://github.com/Kriptel/RuleScript.git dev
- Haxelib :
Adding the library to your project:
Hxml :
-lib rulescriptLime/OpenFL :
<haxelibname="rulescript"/>