Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @:structInit instead of seperate typedef for IrisConfig. #8

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crowplexus/iris/Iris.hx
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ class Iris {
* will trace "Hello World!" to the standard output.
* @param scriptCode the script to be parsed, e.g:
*/
public function new(scriptCode: String, ?config: AutoIrisConfig): Void {
public function new(scriptCode: String, ?config: IrisConfig): Void {
if (config == null)
config = new IrisConfig("Iris", true, true, []);
this.scriptCode = scriptCode;
this.config = IrisConfig.from(config);
this.config = config;
this.config.name = fixScriptName(this.name);

parser = new Parser();
Expand Down
25 changes: 8 additions & 17 deletions crowplexus/iris/IrisConfig.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package crowplexus.iris;

abstract OneOfTwo<T1, T2>(Dynamic) from T1 from T2 to T1 to T2 {}

typedef RawIrisConfig = {
var name: String;
var ?autoRun: Bool;
var ?autoPreset: Bool;
var ?localBlocklist: Array<String>;
};

typedef AutoIrisConfig = OneOfTwo<IrisConfig, RawIrisConfig>;

@:structInit
class IrisConfig {
public var name: String = null;
public var name: String;
public var autoRun: Bool = true;
public var autoPreset: Bool = true;
@:unreflective public var localBlocklist: Array<String> = [];
Expand All @@ -33,10 +23,11 @@ class IrisConfig {
this.localBlocklist = localBlocklist;
}

public static function from(d: AutoIrisConfig): IrisConfig {
if (d != null && Std.isOfType(d, IrisConfig))
return d;
var d: RawIrisConfig = cast d;
return new IrisConfig(d.name, d.autoRun, d.autoPreset, d.localBlocklist);
@:deprecated('IrisConfig.from is deprecated! It\'s not needed anymore!')
public static function from(d: IrisConfig): IrisConfig {
return d;
}
}

@:deprecated('RawIrisConfig is deprecated! Use IrisConfig instead! (IrisConfig supports structInit, only the type needs to be changed)')
class RawIrisConfig extends IrisConfig {}