From e4861a606aa537d302970667bc3621b4bb420f07 Mon Sep 17 00:00:00 2001 From: Jaime Humberto Macias Bustamante Date: Mon, 4 Aug 2025 13:40:48 -0700 Subject: [PATCH] Features Documentation --- README.md | 7 ++-- docs/FEATURES.md | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 docs/FEATURES.md diff --git a/README.md b/README.md index fa26589..32f0e6d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ hscript-improved ======= +- [Features](docs/FEATURES.md) + How to install ``` haxelib git hscript-improved https://github.com/CodenameCrew/hscript-improved.git @@ -18,8 +20,9 @@ or set this in build.hxml -D CUSTOM_CLASSES ``` -Current Custom Class Limitations : -- For now, you can only override functions from the current class, not from the extended part, like you cant override update in FlxText because FlxText doesnt have a update function overriden. +Current Custom Class Limitations : + +- For now, you can only override functions from the current class, not from the extended part, like you cant override update in FlxText because FlxText doesnt have a update function overriden. - You cannot create custom classes that extends a typed class (those ones that has ``), this will be implemented in the future. ----------- diff --git a/docs/FEATURES.md b/docs/FEATURES.md new file mode 100644 index 0000000..94e14ea --- /dev/null +++ b/docs/FEATURES.md @@ -0,0 +1,83 @@ +# FEATURES + +- Custom Classes + - Final Classes + - Static Classes + - Allow for type check (`is`) + - Allow extending other custom classes +- Enums + + ```haxe + enum TypeValue { + NUMBER(n:Int); + DECIMAL(d:Float, ?p:Int); + CHARACTER(s:String); + BOOLEAN(b:Bool); + } + + var type = TypeValue.DECIMAL(10.1234, 2); + // You need to type the full enum field for each case + // i.e. you can't type the enum field directly (limitation for now) + switch(type) { + case TypeValue.NUMBER(number): + trace("number: " + number); + case TypeValue.DECIMAL(decimal, precision): + if(precision != null) + trace("decimal: " + decimal + " | rounded decimal: " + roundDecimal(decimal, precision)); + else + trace("decimal: " + decimal); + case TypeValue.CHARACTER(char): + trace("character: " + char); + default: + trace("unknown type"); + } + + function roundDecimal(Value:Float, Precision:Int) { + var mult:Float = Math.pow(10, Precision); + return Math.fround(Value * mult) / mult; + } + ``` + + - Enum matching with arguments for switch statements (for real and scripted enums) +- Property Fields (`(get, set)` variables) + + ```haxe + public var myvar(get, set):Int; + var _myvar:Int = 10; + + function get_myvar():Int { + return _myvar; + } + + function set_myvar(val:Int):Int { + if(val > 10) return _myvar = val; + return val; + } + ``` + + - `@:isVar` metadata support + +- Static extension (`using`) + + ```haxe + using StringTools; + + class IntExtender { + static public function triple(i:Int) { + return i * 3; + } + } + + // need to create/import the custom class + // before setting the extension (limitation for now) + using IntExtender; + + var str = " Hello World! "; + trace(str.trim()); // "Hello World!" + trace(12.triple()); // 36 + ``` + + - Support for real and custom classes +- Misc. + - Allow using type parameters for creating objects (i.e. `var a = new TypedObject();`) + - Allow `package` declaration. Ignored by the interpreter.