Skip to content

a Haxe Script fork, intended to add features and fix issues with the original hscript.

License

Notifications You must be signed in to change notification settings

crowplexus/hscript-iris

Repository files navigation

HScript Iris


a HScript extension made to make the process of creating a script way easier.


Brought to you by:

INSTALLATION

For stable versions, use this

haxelib install hscript-iris

For unstable versions however, use this

haxelib git hscript-iris https://github.com/crowplexus/hscript-iris/

Once this is done, go to your Project File, whether that be a build.hxml for Haxe Projects, or Project.xml for OpenFL and Flixel projects, and add hscript-iris to your libraries


SETUP

Haxe Project Example

--library hscript-iris
# this is optional and can be added if wanted
# provides descriptive traces and better error handling at runtime
-D hscriptPos

OpenFL / Flixel Project Example

<haxelib name="hscript-iris" />
<haxedef name="hscriptPos" />

FEATURES

  • Improved Error Handling (Completed-ish)?

  • Imports (i.e: import ClassPackageAndName;)

    • Import Aliases (i.e: import ClassPackageAndName as ClassAlias;)
    • Using Keyword (i.e: using StringTools;)
  • Finals

  • Enums

    • Abstract Enums
  • Typedefs

    • Redirects
    • Class Redirect (automatic import)
  • Classes? (we, as developers, are unsure if this is necessary, alright?)

  • Regex?

  • Sandboxing

  • Automatic instance finding (this variable would be set for scripts, which allows being able to access variables from a set class without having to type it out, i.e: PlayState.instance)

  • Operators

    • Null Coalescing Operator (??, ??=)

USAGE

Initializing a Iris Script should be fairly easy and very much self-explanatory

// *
// assets/scripts/hi.hx
// *

// import somepackage.SomeModule;

final greeting:String = "Hello from Iris!";

function sayHello() {
	trace(greeting);

	/*
	// if you try this, this function will crash as `greeting` is a constant value
	greeting = "Uh Oh!";
	// if SomeModule was imported, you can use it here!
	var module:SomeModule = new SomeModule();
	*/
}

function countUpTo(number:Int) {
	for (i in 1...number+1)
		trace(i);
}

// *
// * src/Main.hx
// *

import crowplexus.iris.Iris;
import crowplexus.iris.IrisConfig;

class Main {
	static function main():Void {
		// reminder that the rules are completely optional.
		final rules:RawIrisConfig = {name: "My Script", autoRun: false, autoPreset: true};
		final getText:String->String = #if sys sys.io.File.getContent #elseif openfl openfl.utils.Assets.getText #end;
		var myScript:Iris = new Iris(getText("assets/scripts/hi.hx"), rules);

		// this is necessary in case the `autoRun` rule is disabled when initializing the script, if not it will initialize by itself.
		myScript.execute();

		myScript.call("sayHello"); // prints "Hello from Iris!"
		myScript.call("countUpTo", [5]); // prints "1, 2, 3, 4, 5"
	}
}

About

a Haxe Script fork, intended to add features and fix issues with the original hscript.

Resources

License

Stars

Watchers

Forks

Languages