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

Watch: avoid multiple Expr parses, closes #1886 #2004

Merged
merged 5 commits into from
Jan 11, 2017
Merged
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
10 changes: 10 additions & 0 deletions flixel/system/debug/console/ConsoleUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions flixel/system/debug/watch/Watch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions flixel/system/debug/watch/WatchEntry.hx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class WatchEntry extends Sprite implements IFlxDestroyable
{
case FIELD(_, _): 0xFFFFFF;
case QUICK(_): 0xA5F1ED;
case EXPRESSION(_): 0xC4FE83;
case EXPRESSION(_, _): 0xC4FE83;
}
}

Expand Down Expand Up @@ -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(_):
}
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion flixel/system/debug/watch/WatchEntryData.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package flixel.system.debug.watch;

#if hscript
import hscript.Expr;
#end

enum WatchEntryData
{
/**
Expand All @@ -13,5 +17,5 @@ enum WatchEntryData
/**
* Haxe expression evaluated with hscript.
*/
EXPRESSION(expression:String);
EXPRESSION(expression:String, parsedExpr: #if hscript Expr #else String #end);
}
16 changes: 12 additions & 4 deletions flixel/system/frontEnds/WatchFrontEnd.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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
}

Expand Down