diff --git a/flixel/system/debug/completion/CompletionHandler.hx b/flixel/system/debug/completion/CompletionHandler.hx index 56b2369836..d6f96d4e70 100644 --- a/flixel/system/debug/completion/CompletionHandler.hx +++ b/flixel/system/debug/completion/CompletionHandler.hx @@ -8,7 +8,7 @@ using flixel.util.FlxArrayUtil; using flixel.util.FlxStringUtil; using StringTools; -#if hscript +#if (polymod || hscript) import flixel.system.debug.console.ConsoleUtil; #end @@ -72,7 +72,7 @@ class CompletionHandler function invokeCompletion(path:String, isPeriod:Bool) { - #if hscript + #if (polymod || hscript) var items:Array = null; try @@ -104,7 +104,7 @@ class CompletionHandler function getGlobals():Array { - #if hscript + #if (polymod || hscript) return ConsoleUtil.interp.getGlobals().sortAlphabetically(); #else return []; @@ -135,7 +135,7 @@ class CompletionHandler function selectionChanged(selectedItem:String) { - #if hscript + #if (polymod || hscript) try { var lastWord = getLastWord(input.text); diff --git a/flixel/system/debug/console/Console.hx b/flixel/system/debug/console/Console.hx index b91e865c62..2442793162 100644 --- a/flixel/system/debug/console/Console.hx +++ b/flixel/system/debug/console/Console.hx @@ -11,7 +11,7 @@ import openfl.text.TextFormat; #if sys import openfl.events.MouseEvent; #end -#if hscript +#if (polymod || hscript) import openfl.events.FocusEvent; import openfl.events.KeyboardEvent; import openfl.text.TextFieldType; @@ -30,7 +30,7 @@ class Console extends Window /** * The text that is displayed in the console's input field by default. */ - static inline var DEFAULT_TEXT:String = #if hscript "(Click here / press [Tab] to enter command. Type 'help' for help.)" #else "Using the console requires hscript - please run 'haxelib install hscript'." #end; + static inline var DEFAULT_TEXT:String = #if (polymod || hscript) "(Click here / press [Tab] to enter command. Type 'help' for help.)" #else "Using the console requires hscript." #end; /** * Map containing all registered Objects. You can use registerObject() or add them directly to this map. @@ -75,7 +75,7 @@ class Console extends Window this.completionList = completionList; completionList.setY(y + Window.HEADER_HEIGHT); - #if hscript + #if (polymod || hscript) ConsoleUtil.init(); #end @@ -106,7 +106,7 @@ class Console extends Window function registerEventListeners() { - #if hscript + #if (polymod || hscript) input.type = TextFieldType.INPUT; input.addEventListener(FocusEvent.FOCUS_IN, onFocus); input.addEventListener(FocusEvent.FOCUS_OUT, onFocusLost); @@ -194,7 +194,7 @@ class Console extends Window FlxG.game.debugger.onMouseFocusLost(); } - #if hscript + #if (polymod || hscript) function onKeyDown(e:KeyboardEvent) { if (completionList.visible) @@ -302,7 +302,7 @@ class Console extends Window public function registerFunction(alias:String, func:Dynamic, ?helpText:String) { registeredFunctions.set(alias, func); - #if hscript + #if (polymod || hscript) ConsoleUtil.registerFunction(alias, func); #end @@ -319,7 +319,7 @@ class Console extends Window public function registerObject(alias:String, object:Dynamic) { registeredObjects.set(alias, object); - #if hscript + #if (polymod || hscript) ConsoleUtil.registerObject(alias, object); #end } @@ -334,7 +334,7 @@ class Console extends Window { registeredObjects.remove(alias); registeredFunctions.remove(alias); - #if hscript + #if (polymod || hscript) ConsoleUtil.removeByAlias(alias); #end } @@ -354,7 +354,7 @@ class Console extends Window if (registeredObjects[alias] == object) { registeredObjects.remove(alias); - #if hscript + #if (polymod || hscript) ConsoleUtil.removeByAlias(alias); #end break; @@ -377,7 +377,7 @@ class Console extends Window if (registeredFunctions[alias] == func) { registeredFunctions.remove(alias); - #if hscript + #if (polymod || hscript) ConsoleUtil.removeByAlias(alias); #end break; @@ -432,7 +432,7 @@ class Console extends Window { super.destroy(); - #if hscript + #if (polymod || hscript) input.removeEventListener(FocusEvent.FOCUS_IN, onFocus); input.removeEventListener(FocusEvent.FOCUS_OUT, onFocusLost); input.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); diff --git a/flixel/system/debug/console/ConsoleUtil.hx b/flixel/system/debug/console/ConsoleUtil.hx index ae78b304ff..8eae08591b 100644 --- a/flixel/system/debug/console/ConsoleUtil.hx +++ b/flixel/system/debug/console/ConsoleUtil.hx @@ -7,9 +7,14 @@ using flixel.util.FlxStringUtil; using flixel.util.FlxArrayUtil; using StringTools; -#if hscript +#if polymod +import polymod.hscript._internal.Expr; +import polymod.hscript._internal.Parser; +import polymod.hscript._internal.Interp as HScriptInterp; +#elseif hscript import hscript.Expr; import hscript.Parser; +import hscript.Interp as HScriptInterp; #end /** @@ -17,7 +22,7 @@ import hscript.Parser; */ class ConsoleUtil { - #if hscript + #if (polymod || hscript) /** * The hscript parser to make strings into haxe code. */ @@ -37,7 +42,11 @@ class ConsoleUtil parser.allowJSON = true; parser.allowTypes = true; + #if (polymod) + interp = new Interp(null, null); + #else interp = new Interp(); + #end } /** @@ -172,11 +181,8 @@ class ConsoleUtil } } -/** - * hscript doesn't use property access by default... have to make our own. - */ -#if hscript -private class Interp extends hscript.Interp +#if (polymod || hscript) +private class Interp extends HScriptInterp { public function getGlobals():Array { @@ -191,6 +197,7 @@ private class Interp extends hscript.Interp return array; } + #if (hscript && !polymod) override function get(o:Dynamic, f:String):Dynamic { if (o == null) @@ -205,5 +212,6 @@ private class Interp extends hscript.Interp Reflect.setProperty(o, f, v); return v; } + #end } -#end +#end \ No newline at end of file diff --git a/flixel/system/debug/watch/WatchEntry.hx b/flixel/system/debug/watch/WatchEntry.hx index c54558b9b9..6b20e91e62 100644 --- a/flixel/system/debug/watch/WatchEntry.hx +++ b/flixel/system/debug/watch/WatchEntry.hx @@ -13,7 +13,7 @@ import openfl.text.TextFormat; using flixel.util.FlxStringUtil; -#if hscript +#if (polymod || hscript) import flixel.system.debug.console.ConsoleUtil; #end @@ -120,7 +120,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable case FIELD(object, field): Reflect.getProperty(object, field); case EXPRESSION(_, parsedExpr): - #if hscript + #if (polymod || hscript) ConsoleUtil.runExpr(parsedExpr); #else "hscript is not installed"; diff --git a/flixel/system/debug/watch/WatchEntryData.hx b/flixel/system/debug/watch/WatchEntryData.hx index 4a243433d5..f9ecef9a43 100644 --- a/flixel/system/debug/watch/WatchEntryData.hx +++ b/flixel/system/debug/watch/WatchEntryData.hx @@ -1,6 +1,8 @@ package flixel.system.debug.watch; -#if hscript +#if polymod +import polymod.hscript._internal.Expr; +#elseif hscript import hscript.Expr; #end @@ -19,7 +21,7 @@ enum WatchEntryData /** * Haxe expression evaluated with hscript. */ - EXPRESSION(expression:String, parsedExpr:#if hscript Expr #else String #end); + EXPRESSION(expression:String, parsedExpr:#if (polymod || hscript) Expr #else String #end); /** * A function that returns the value to display. diff --git a/flixel/system/frontEnds/WatchFrontEnd.hx b/flixel/system/frontEnds/WatchFrontEnd.hx index 92ad05be5e..707210911a 100644 --- a/flixel/system/frontEnds/WatchFrontEnd.hx +++ b/flixel/system/frontEnds/WatchFrontEnd.hx @@ -1,7 +1,7 @@ package flixel.system.frontEnds; import flixel.FlxG; -#if hscript +#if (polymod || hscript) import flixel.system.debug.console.ConsoleUtil; #end @@ -84,7 +84,7 @@ class WatchFrontEnd { #if FLX_DEBUG var parsedExpr = null; - #if hscript + #if (polymod || hscript) parsedExpr = ConsoleUtil.parseCommand(expression); #end window.add(displayName == null ? expression : displayName, EXPRESSION(expression, parsedExpr));