}
result = resultArr;
+ } else if (str.IsObjectType<Function>()) {
+ result = EvaluateFunction(str, resolvers, cr, missingMacro, escapeFn, resolvedMacros, useResolvedMacros, 0);
} else {
- BOOST_THROW_EXCEPTION(std::invalid_argument("Command is not a string or array."));
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Macro is not a string or array."));
}
return result;
resolvedMacros, useResolvedMacros, recursionLevel);
}
+Value MacroProcessor::EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
+ const CheckResult::Ptr& cr, String *missingMacro,
+ const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
+ bool useResolvedMacros, int recursionLevel)
+{
+ Dictionary::Ptr resolvers_this = new Dictionary();
+
+ BOOST_FOREACH(const ResolverSpec& resolver, resolvers) {
+ resolvers_this->Set(resolver.first, resolver.second);
+ }
+
+ resolvers_this->Set("macro", new Function(boost::bind(&MacroProcessor::InternalResolveMacrosShim,
+ _1, boost::cref(resolvers), cr, missingMacro, boost::cref(escapeFn), resolvedMacros, useResolvedMacros,
+ recursionLevel)));
+
+ ScriptFrame frame(resolvers_this);
+ std::vector<Value> args;
+ return func->Invoke(args);
+}
+
Value MacroProcessor::InternalResolveMacros(const String& str, const ResolverList& resolvers,
const CheckResult::Ptr& cr, String *missingMacro,
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
}
if (resolved_macro.IsObjectType<Function>()) {
- Function::Ptr func = resolved_macro;
-
- if (!resolvers_this) {
- resolvers_this = new Dictionary();
-
- BOOST_FOREACH(const ResolverSpec& resolver, resolvers) {
- resolvers_this->Set(resolver.first, resolver.second);
- }
-
- resolvers_this->Set("macro", new Function(boost::bind(&MacroProcessor::InternalResolveMacrosShim,
- _1, boost::cref(resolvers), cr, missingMacro, boost::cref(escapeFn), resolvedMacros, useResolvedMacros,
- recursionLevel)));
- }
-
- ScriptFrame frame(resolvers_this);
- std::vector<Value> args;
- resolved_macro = func->Invoke(args);
+ resolved_macro = EvaluateFunction(resolved_macro, resolvers, cr, missingMacro, escapeFn,
+ resolvedMacros, useResolvedMacros, recursionLevel);
}
if (!found) {
const CheckResult::Ptr& cr, String *missingMacro,
const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros, int recursionLevel);
+ static Value EvaluateFunction(const Function::Ptr& func, const ResolverList& resolvers,
+ const CheckResult::Ptr& cr, String *missingMacro,
+ const MacroProcessor::EscapeCallback& escapeFn, const Dictionary::Ptr& resolvedMacros,
+ bool useResolvedMacros, int recursionLevel);
+
};
}
arg.Key = kv.first;
bool required = false;
- String argval;
+ Value argval;
if (arginfo.IsObjectType<Dictionary>()) {
Dictionary::Ptr argdict = arginfo;
arg.RepeatKey = argdict->Get("repeat_key");
arg.Order = argdict->Get("order");
- String set_if = argdict->Get("set_if");
+ Value set_if = argdict->Get("set_if");
if (!set_if.IsEmpty()) {
String missingMacro;
- String set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers,
+ Value set_if_resolved = MacroProcessor::ResolveMacros(set_if, macroResolvers,
cr, &missingMacro, MacroProcessor::EscapeCallback(), resolvedMacros,
useResolvedMacros);