diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/context.cc | 15 | ||||
-rw-r--r-- | src/module.cc | 3 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/context.cc b/src/context.cc index a7273a4..b5420ff 100644 --- a/src/context.cc +++ b/src/context.cc @@ -38,6 +38,13 @@ namespace fs = boost::filesystem; std::vector<const Context*> Context::ctx_stack; +// $children is not a config_variable. config_variables have dynamic scope, +// meaning they are passed down the call chain implicitly. +// $children is simply misnamed and shouldn't have included the '$'. +static bool is_config_variable(const std::string &name) { + return name[0] == '$' && name != "$children"; +} + /*! Initializes this context. Optionally initializes a context for an external library */ @@ -80,10 +87,8 @@ void Context::setVariables(const AssignmentList &args, void Context::set_variable(const std::string &name, const Value &value) { - if (name[0] == '$') - this->config_variables[name] = value; - else - this->variables[name] = value; + if (is_config_variable(name)) this->config_variables[name] = value; + else this->variables[name] = value; } void Context::set_constant(const std::string &name, const Value &value) @@ -98,7 +103,7 @@ void Context::set_constant(const std::string &name, const Value &value) Value Context::lookup_variable(const std::string &name, bool silent) const { - if (name[0] == '$') { + if (is_config_variable(name)) { for (int i = ctx_stack.size()-1; i >= 0; i--) { const ValueMap &confvars = ctx_stack[i]->config_variables; if (confvars.find(name) != confvars.end()) diff --git a/src/module.cc b/src/module.cc index 8fb8506..f66c8ef 100644 --- a/src/module.cc +++ b/src/module.cc @@ -180,8 +180,9 @@ AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation } ModuleContext c(ctx, evalctx); - c.initializeModule(*this); + // set $children first since we might have variables depending on it c.set_variable("$children", Value(double(inst->scope.children.size()))); + c.initializeModule(*this); // FIXME: Set document path to the path of the module #if 0 && DEBUG c.dump(this, inst); |