Skip to content

Commit 0f890af

Browse files
committed
Update README.md
1 parent f435175 commit 0f890af

1 file changed

Lines changed: 101 additions & 11 deletions

File tree

README.md

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# RuleScript
22

3-
Hscript addon with imports, usings, string interpolation and more.
3+
Hscript addon with script classes, imports, usings, properties, string interpolation and more.
44

55
## Features:
66

7+
- [Package](#package)
8+
- [Import](#import)
9+
- [Alias](#import-with-alias)
10+
- [Static field](#static-field-import)
11+
- [Using](#using)
12+
- [Property](#property)
13+
- [String interpolation](#string-interpolation)
14+
- [Script Class](#rulescriptedclass)
15+
- [Abstracts in script](#abstracts-in-script)
16+
- [Key => value Iterator](#key--value-iterator)
17+
- [`??` and `??=` operators](#-and--operators)
18+
719
### Package
8-
package keyword (optional).
920
```haxe
1021
package scripts.hello.world;
1122
```
@@ -34,6 +45,17 @@ map.set("Hello","World");
3445
trace(map.get("Hello")); // World
3546
```
3647

48+
### Static field import
49+
```haxe
50+
import Reflect.getProperty;
51+
52+
var a = {
53+
"hello":"world"
54+
};
55+
56+
return getProperty(a,"hello");
57+
```
58+
3759
### Using
3860
```haxe
3961
using Reflect;
@@ -44,6 +66,21 @@ var a = {
4466
trace(a.getProperty("Hello")); // World
4567
```
4668

69+
### Property
70+
```haxe
71+
var _a = 'Hello World';
72+
73+
var a(get,set):String;
74+
75+
function get_a():String
76+
return _a;
77+
78+
function set_a(v:String):String
79+
return _a = v;
80+
81+
trace(a); // Hello World
82+
```
83+
4784
### String interpolation
4885
RuleScript supports [String Interpolation](https://haxe.org/manual/lf-string-interpolation.html), but you can only use identifiers, double quotes string, calls without arguments and `+` operator.
4986
```haxe
@@ -60,6 +97,35 @@ var a = {
6097
trace('${a.a}: ${a.b() + ' ' + a.c(true)}'); // RuleScript: Hello World
6198
```
6299

100+
### RuleScriptedClass
101+
Rulescript supports scripted classes, they can have a strict and non-strict constructor.
102+
103+
Script :
104+
```haxe
105+
class ScriptedClass extends test.ScriptedClassTest
106+
{
107+
public function new(customArg:Int,arg1:String)
108+
{
109+
trace('Constructor.pre: $customArg, $arg1');
110+
111+
super('Super Arg');
112+
113+
trace('Constructor.post: $customArg, $arg1');
114+
}
115+
116+
override public function info()
117+
{
118+
return 'Scripted class, super info: ${super.info()}';
119+
}
120+
}
121+
```
122+
Source :
123+
```haxe
124+
class ScriptedClassTest implements RuleScriptedClass extends SrcClass {}
125+
```
126+
127+
See [`Main.hx`](./test/src/Main.hx#l267), [`ScriptedClassTest.hx`](./test/src/test/ScriptedClassTest.hx), [`ScriptedClass`](./test/scripts/haxe/ScriptedClass.rhx).
128+
63129
### Abstracts in script
64130

65131
`RuleScriptAbstracts.txt` in any classpath :
@@ -83,6 +149,30 @@ trace(HelloWorldAbstract.rulescriptPrint()); // 'Hello World'
83149
```
84150
More templates in [`test/src/Main.hx`](https://github.com/Kriptel/RuleScript/blob/master/test/src/Main.hx).
85151

152+
### Key => value iterator
153+
```haxe
154+
var map = [
155+
'RuleScript' => 'Hello World',
156+
];
157+
158+
for(key => value in map){
159+
trace('$key: $value'); // RuleScript:'Hello World'
160+
}
161+
```
162+
163+
### `??` and `??=` operators
164+
```haxe
165+
trace(null ?? 'Hello World'); // Hello World
166+
167+
var a = 'hello';
168+
169+
a ??= 'world';
170+
trace(a); // hello
171+
172+
a = null;
173+
a ??= 'world';
174+
trace(a) // world
175+
```
86176
# Limitations
87177

88178
- Script `using` callback supports max number of arguments is 8.
@@ -96,17 +186,17 @@ More templates in [`test/src/Main.hx`](https://github.com/Kriptel/RuleScript/blo
96186
# Install
97187

98188
1. Installing lib:
99-
- haxelib version
100-
- Haxelib : `haxelib install rulescript`
101-
- Hmm : `hmm haxelib rulescript`
102-
- github version
189+
- haxelib version
190+
- Haxelib : `haxelib install rulescript`
191+
- Hmm : `hmm haxelib rulescript`
192+
- github version
103193

104-
- Haxelib : `haxelib git rulescript https://github.com/Kriptel/RuleScript.git`
105-
- Hmm : `hmm git rulescript https://github.com/Kriptel/RuleScript.git`
106-
- github version (dev)
194+
- Haxelib : `haxelib git rulescript https://github.com/Kriptel/RuleScript.git`
195+
- Hmm : `hmm git rulescript https://github.com/Kriptel/RuleScript.git`
196+
- github version (dev)
107197

108-
- Haxelib : `haxelib git rulescript https://github.com/Kriptel/RuleScript.git dev`
109-
- Hmm : `hmm git rulescript https://github.com/Kriptel/RuleScript.git dev`
198+
- Haxelib : `haxelib git rulescript https://github.com/Kriptel/RuleScript.git dev`
199+
- Hmm : `hmm git rulescript https://github.com/Kriptel/RuleScript.git dev`
110200
2. Adding lib to your project:
111201

112202
Hxml :

0 commit comments

Comments
 (0)