Skip to content

Commit

Permalink
Resolving functions as variables should result in the consultation of…
Browse files Browse the repository at this point in the history
… the variable resolver
  • Loading branch information
davedelong committed Jan 4, 2014
1 parent b8d7a95 commit 400517b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
3 changes: 3 additions & 0 deletions DDMathParser/DDMathEvaluator.m
Expand Up @@ -109,6 +109,9 @@ - (DDExpression *)resolveFunction:(_DDFunctionExpression *)functionExpression va
// see if we have a variable value with the same name as the function
id variableValue = [variables objectForKey:functionName];
NSNumber *n = [self _evaluateValue:variableValue withSubstitutions:variables error:error];
if (n == nil) {
n = [self variableWithName:functionName];
}
if (n != nil) {
e = [DDExpression numberExpressionWithNumber:n];
}
Expand Down
12 changes: 1 addition & 11 deletions Demo/DemoController.m
Expand Up @@ -30,6 +30,7 @@ - (void)awakeFromNib {
- (DDMathEvaluator *)evaluator {
if (evaluator == nil) {
evaluator = [[DDMathEvaluator alloc] init];
evaluator.resolvesFunctionsAsVariables = YES;

__weak __typeof(self) weakSelf = self;
[evaluator setVariableResolver:^(NSString *variable) {
Expand All @@ -39,17 +40,6 @@ - (DDMathEvaluator *)evaluator {
}
return @0;
}];

[evaluator setFunctionResolver:^(NSString *functionName) {
return ^(NSArray *args, NSDictionary *vars, DDMathEvaluator *eval, NSError **error) {
__strong __typeof(weakSelf) strongSelf = weakSelf;
NSNumber *number = @0;
if (strongSelf) {
number = [strongSelf->variables objectForKey:functionName];
}
return [DDExpression numberExpressionWithNumber:number];
};
}];
}

return evaluator;
Expand Down

0 comments on commit 400517b

Please sign in to comment.