Skip to content

Repository files navigation

RuleScript

Hscript addon featuring script classes, imports, usings, properties, string interpolation and more.

Features:

Package

packagescripts.hello.world;

Import

importhaxe.ds.StringMap;
varmap=newStringMap();
map.set("Hello","World");
trace(map.get("Hello")); // World

Import with alias

Supports both the as and in aliases.

importhaxe.ds.StringMapasStrMap;
varmap=newStrMap();
map.set("Hello","World");
trace(map.get("Hello")); // World
importhaxe.ds.StringMapinStrMap;
varmap=newStrMap();
map.set("Hello","World");
trace(map.get("Hello")); // World

Static field import

importReflect.getProperty;
vara= {
"hello":"world"
};
returngetProperty(a,"hello");

Using

usingReflect;
vara= {
"Hello":"World"
};
trace(a.getProperty("Hello")); // World

Property

var_a='Hello World';
vara(get,set):String;
functionget_a():Stringreturn_a;
functionset_a(v:String):Stringreturn_a=v;
trace(a); // Hello World

String interpolation

vara='Hello';
trace('RuleScript: $a World'); // RuleScript: Hello World
vara= {
a:'RuleScript',
b: () ->'Hello',
c: (a) ->a?'World':'';
};
trace('${a.a}: ${a.b() +''+a.c(true)}'); // RuleScript: Hello World

RuleScriptedClass

RuleScript 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.

Abstracts in script

RuleScriptAbstracts.txt in any classpath :

test.HelloWorldAbstract

test/HelloWorldAbstract.hx :

abstractHelloWorldAbstract(String) fromStringtoString
{
publicstaticfunctionrulescriptPrint():HelloWorldAbstractreturn'Hello World';
}

Script :

importtest.HelloWorldAbstract;
trace(HelloWorldAbstract.rulescriptPrint()); // Hello World

More templates can be found in test/src/Main.hx.

Key => value iterator

varmap= [
'RuleScript'=>'Hello World',
];
for(key=>valueinmap){
trace('$key: $value'); // RuleScript: Hello World
}

?? and ??= operators

trace(null??'Hello World'); // Hello Worldvara='hello';
a??='world';
trace(a); // helloa=null;
a??='world';
trace(a) // world

Rest

varf=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 !

Limitations

  • Script using callbacks support a maximum of 8 arguments.
  • Wildcard imports are not supported.
  • AbstractMacro only supports staticabstract fields.

To Do

  • Improve hscript module parser

Install

  1. Installing the library:

    • haxelib version

      • Haxelib : haxelib install rulescript
      • Hmm : hmm haxelib rulescript
    • github version

      • Haxelib : haxelib git rulescript https://github.com/Kriptel/RuleScript.git
      • Hmm : hmm git rulescript https://github.com/Kriptel/RuleScript.git
    • 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
  2. Adding the library to your project:

    Hxml :

    -lib rulescript

    Lime/OpenFL :

    <haxelibname="rulescript"/>

About

Hscript addon featuring script classes, imports, usings, properties, string interpolation and more.

Topics

Resources

Stars

38 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages