[go: up one dir, main page]

rulescript

Hscript addon featuring script classes, imports, usings, properties, string interpolation and more.
https://github.com/Kriptel/RuleScript

To install, run:

haxelib install rulescript 0.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

RuleScript

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

Features:

Package

package scripts.hello.world;

Import

import haxe.ds.StringMap;

var map = new StringMap();
map.set("Hello","World");
trace(map.get("Hello")); // World

Import with alias

Supports both the as and in aliases.

import haxe.ds.StringMap as StrMap;

var map = new StrMap();
map.set("Hello","World");
trace(map.get("Hello")); // World
import haxe.ds.StringMap in StrMap;

var map = new StrMap();
map.set("Hello","World");
trace(map.get("Hello")); // World

Static field import

import Reflect.getProperty;

var a = {
	"hello":"world"
};

return getProperty(a,"hello");

Using

using Reflect;

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

Property

var _a = 'Hello World';

var a(get,set):String;

function get_a():String
	return _a;

function set_a(v:String):String
	return _a = v;

trace(a); // Hello World

String interpolation

var a = 'Hello';
trace('RuleScript: $a World'); // RuleScript: Hello World
var a = {
    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 :

class ScriptedClass extends test.ScriptedClassTest
{
	public function new(customArg:Int,arg1:String)
	{
		trace('Constructor.pre: $customArg, $arg1');
		
		super('Super Arg');

		trace('Constructor.post: $customArg, $arg1');	
	}

	override public function info()
	{
		return 'Scripted class, super info: ${super.info()}';
	}
}

Source :

class ScriptedClassTest implements RuleScriptedClass extends SrcClass {}

See Main.hx, ScriptedClassTest.hx, ScriptedClass.

Abstracts in script

RuleScriptAbstracts.txt in any classpath :

test.HelloWorldAbstract

test/HelloWorldAbstract.hx :

abstract HelloWorldAbstract(String) from String to String
{
	public static function rulescriptPrint():HelloWorldAbstract
		return 'Hello World';
}

Script :

import test.HelloWorldAbstract;

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

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

Key => value iterator

var map = [
	'RuleScript' => 'Hello World',
];

for(key => value in map){
	trace('$key: $value'); // RuleScript: Hello World
}

?? and ??= operators

trace(null ?? 'Hello World'); // Hello World

var a = 'hello';

a ??= 'world';
trace(a); // hello

a = null;
a ??= 'world';
trace(a) // world

Rest

var f = 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 static abstract 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`
  1. Adding the library to your project:

    Hxml :

    -lib rulescript

    Lime/OpenFL :

    <haxelib name="rulescript"/>
Contributors
Kriptel
Version
0.2.0
Published
11 months ago
Dependencies
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub