diff --git a/flixel/system/debug/console/ConsoleUtil.hx b/flixel/system/debug/console/ConsoleUtil.hx index 6cfe4d2e66..04dec0a8da 100644 --- a/flixel/system/debug/console/ConsoleUtil.hx +++ b/flixel/system/debug/console/ConsoleUtil.hx @@ -62,6 +62,16 @@ class ConsoleUtil return interp.expr(parseCommand(Input)); } + /** + * Runs the input expression. + * @param Parsed The parsed form of the user's input command. + * @return Whatever the input code evaluates to. + */ + public static function runExpr(expr:Expr):Dynamic + { + return interp.expr(expr); + } + /** * Register a new object to use in any command. * diff --git a/flixel/system/debug/watch/Watch.hx b/flixel/system/debug/watch/Watch.hx index 951d942b3d..4d61c12a51 100644 --- a/flixel/system/debug/watch/Watch.hx +++ b/flixel/system/debug/watch/Watch.hx @@ -60,7 +60,7 @@ class Watch extends Window object == null || field == null; case QUICK(value): displayName.isNullOrEmpty(); - case EXPRESSION(expression): + case EXPRESSION(expression, _): expression.isNullOrEmpty(); } } @@ -69,7 +69,7 @@ class Watch extends Window { for (entry in entries) { - if (data.match(QUICK(_))) + if (data == null || data.match(QUICK(_))) { if (entry.displayName == displayName) return entry; diff --git a/flixel/system/debug/watch/WatchEntry.hx b/flixel/system/debug/watch/WatchEntry.hx index 1a7e94501f..b582340db0 100644 --- a/flixel/system/debug/watch/WatchEntry.hx +++ b/flixel/system/debug/watch/WatchEntry.hx @@ -57,7 +57,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable { case FIELD(_, _): 0xFFFFFF; case QUICK(_): 0xA5F1ED; - case EXPRESSION(_): 0xC4FE83; + case EXPRESSION(_, _): 0xC4FE83; } } @@ -93,7 +93,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable { case FIELD(object, field): setNameText(object.getClassName(true) + "." + field); - case EXPRESSION(expression): + case EXPRESSION(expression, _): setNameText(expression); case QUICK(_): } @@ -112,9 +112,9 @@ class WatchEntry extends Sprite implements IFlxDestroyable { case FIELD(object, field): Reflect.getProperty(object, field); - case EXPRESSION(expression): + case EXPRESSION(_, parsedExpr): #if hscript - ConsoleUtil.runCommand(expression); + ConsoleUtil.runExpr(parsedExpr); #else "hscript is not installed"; #end diff --git a/flixel/system/debug/watch/WatchEntryData.hx b/flixel/system/debug/watch/WatchEntryData.hx index 4d86a8a349..f433267411 100644 --- a/flixel/system/debug/watch/WatchEntryData.hx +++ b/flixel/system/debug/watch/WatchEntryData.hx @@ -1,5 +1,9 @@ package flixel.system.debug.watch; +#if hscript +import hscript.Expr; +#end + enum WatchEntryData { /** @@ -13,5 +17,5 @@ enum WatchEntryData /** * Haxe expression evaluated with hscript. */ - EXPRESSION(expression:String); + EXPRESSION(expression:String, parsedExpr: #if hscript Expr #else String #end); } \ No newline at end of file diff --git a/flixel/system/frontEnds/WatchFrontEnd.hx b/flixel/system/frontEnds/WatchFrontEnd.hx index 78159c3173..d404a781b5 100644 --- a/flixel/system/frontEnds/WatchFrontEnd.hx +++ b/flixel/system/frontEnds/WatchFrontEnd.hx @@ -2,6 +2,10 @@ package flixel.system.frontEnds; import flixel.FlxG; +#if hscript +import flixel.system.debug.console.ConsoleUtil; +#end + class WatchFrontEnd { public function new() {} @@ -72,20 +76,24 @@ class WatchFrontEnd public function addExpression(expression:String, ?displayName:String):Void { #if FLX_DEBUG - FlxG.game.debugger.watch.add(displayName, EXPRESSION(expression)); + var parsedExpr = null; + #if hscript + parsedExpr = ConsoleUtil.parseCommand(expression); + #end + FlxG.game.debugger.watch.add(displayName == null ? expression : displayName, EXPRESSION(expression, parsedExpr)); #end } /** * Remove an expression from the watch list in the debugger. * - * @param expression The Haxe expression that you want to remove. + * @param displayName The display name of the registered expression, if you supplied one, or the Haxe expression that you want to remove, in string form. * @since 4.1.0 */ - public function removeExpression(expression:String):Void + public function removeExpression(displayName:String):Void { #if FLX_DEBUG - FlxG.game.debugger.watch.remove(null, EXPRESSION(expression)); + FlxG.game.debugger.watch.remove(displayName, null); #end }