Skip to content

[FEATURE / REWORK] New Implementation For Scripted Classes #201

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

Open
wants to merge 3 commits into
base: experiment/static-fields
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
20 changes: 11 additions & 9 deletions polymod/Polymod.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import polymod.format.JsonHelp;
import polymod.format.ParseRules;
import polymod.fs.PolymodFileSystem;
#if hscript
import polymod.hscript._internal.PolymodScriptClass;
import polymod.hscript._internal.PolymodScriptManager;
#end
import polymod.util.DependencyUtil;
import polymod.util.VersionUtil;
Expand Down Expand Up @@ -193,7 +193,7 @@ enum Framework
}


@:allow(polymod.hscript._internal.PolymodScriptClass)
@:allow(polymod.hscript._internal.PolymodScriptManager)
class Polymod
{
/**
Expand Down Expand Up @@ -337,9 +337,11 @@ class Polymod
} else {
Polymod.registerAllScriptClasses();

var classList = polymod.hscript._internal.PolymodScriptClass.listScriptClasses();
var classList = PolymodScriptManager.instance.listScriptClasses();
Polymod.notice(PolymodErrorCode.SCRIPT_PARSED, 'Parsed and registered ${classList.length} scripted classes.');
}

PolymodScriptManager.instance.validateImports();
}
#else
if (params.useScriptedClasses)
Expand Down Expand Up @@ -654,7 +656,7 @@ class Polymod
{
#if hscript
@:privateAccess
polymod.hscript._internal.PolymodScriptClass.clearScriptedClasses();
PolymodScriptManager.instance.clearScriptedClasses();
polymod.hscript.HScriptable.ScriptRunner.clearScripts();
#else
Polymod.warning(SCRIPT_HSCRIPT_NOT_INSTALLED, "Cannot register script classes, HScript is not available.");
Expand Down Expand Up @@ -688,7 +690,7 @@ class Polymod
if (!Polymod.assetLibrary.exists(path)) throw 'Couldn\'t find file "$textPath"';
}
Polymod.debug('Registering script class "$path"');
polymod.hscript._internal.PolymodScriptClass.registerScriptClassByPath(path);
PolymodScriptManager.instance.registerScriptClassByPath(path);
}
}
}
Expand Down Expand Up @@ -724,7 +726,7 @@ class Polymod
if (!Polymod.assetLibrary.exists(path)) throw 'Couldn\'t find file "$textPath" (tried libraries ${libraryIds})';
}
Polymod.debug('Fetching script class "$path"');
var future = polymod.hscript._internal.PolymodScriptClass.registerScriptClassByPathAsync(path);
var future = PolymodScriptManager.instance.registerScriptClassByPathAsync(path);
if (future != null) futures.push(future);
}
}
Expand Down Expand Up @@ -794,15 +796,15 @@ class Polymod
*/
public static function addImportAlias(importAlias:String, importClass:Class<Dynamic>):Void {
#if hscript
PolymodScriptClass.importOverrides.set(importAlias, importClass);
PolymodScriptManager.instance.importOverrides.set(importAlias, importClass);
#else
Polymod.warning(PolymodErrorCode.SCRIPT_HSCRIPT_NOT_INSTALLED, 'Scripted classes imports were requested, but hscript is not installed.');
#end
}

public static function removeImportAlias(importAlias:String):Void {
#if hscript
PolymodScriptClass.importOverrides.remove(importAlias);
PolymodScriptManager.instance.importOverrides.remove(importAlias);
#else
Polymod.warning(PolymodErrorCode.SCRIPT_HSCRIPT_NOT_INSTALLED, 'Scripted classes imports were requested, but hscript is not installed.');
#end
Expand All @@ -815,7 +817,7 @@ class Polymod
*/
public static function addDefaultImport(importClass:Class<Dynamic>, ?importAlias:String):Void {
#if hscript
PolymodScriptClass.defaultImports.set(importAlias == null ? Type.getClassName(importClass) : importAlias, importClass);
PolymodScriptManager.instance.defaultImports.set(importAlias == null ? Type.getClassName(importClass) : importAlias, importClass);
#else
Polymod.warning(PolymodErrorCode.SCRIPT_HSCRIPT_NOT_INSTALLED, 'Scripted classes imports were requested, but hscript is not installed.');
#end
Expand Down
2 changes: 1 addition & 1 deletion polymod/hscript/HScriptable.hx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Script
public static function buildInterp():polymod.hscript._internal.PolymodInterpEx
{
// Arguments are only needed in a scripted class context.
return new polymod.hscript._internal.PolymodInterpEx(null, null);
return new polymod.hscript._internal.PolymodInterpEx(null);
}

public function new(script:String, ?origin:String = null)
Expand Down
87 changes: 0 additions & 87 deletions polymod/hscript/HScriptedClass.hx

This file was deleted.

Loading