diff options
author | Łukasz Stelmach <stlman@poczta.fm> | 2013-08-18 15:18:43 (GMT) |
---|---|---|
committer | Łukasz Stelmach <stlman@poczta.fm> | 2013-08-18 15:19:49 (GMT) |
commit | 400d28d753aa8af8de60a7f82851ffdc3cdae672 (patch) | |
tree | 3e76d4c4449556c26d48073200956045bc092111 /src/module.cc | |
parent | d67e0129161a98f852ed2685f43e7eb7c7538bf0 (diff) |
Enable module stack introspection from within an SCAD script
The _current_module and _parent_module variables have been replaced
by a built-in function parent_module(n). It takes one numeric parameter n,
and returns n-th element from the module stack. If no argument provided,
n defaults to 1 and the function returns the name of the direct parent
module. If n is equal 0 current module name is returned.
Diffstat (limited to 'src/module.cc')
-rw-r--r-- | src/module.cc | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/module.cc b/src/module.cc index 970dd56..9c3541f 100644 --- a/src/module.cc +++ b/src/module.cc @@ -153,7 +153,7 @@ std::vector<AbstractNode*> IfElseModuleInstantiation::instantiateElseChildren(co return this->else_scope.instantiateChildren(evalctx); } -std::stack<std::string> Module::stack; +std::deque<std::string> Module::module_stack; Module::~Module() { @@ -183,20 +183,18 @@ AbstractNode *Module::instantiate(const Context *ctx, const ModuleInstantiation ModuleContext c(ctx, evalctx); c.initializeModule(*this); - c.set_variable("_current_module", inst->name()); - if (!stack.empty()) - c.set_variable("_parent_module", stack.top()); + module_stack.push_back(inst->name()); + c.set_variable("$parent_modules", Value(double(module_stack.size()))); c.set_variable("$children", Value(double(inst->scope.children.size()))); // FIXME: Set document path to the path of the module #if 0 && DEBUG c.dump(this, inst); #endif - stack.push(inst->name()); AbstractNode *node = new AbstractNode(inst); std::vector<AbstractNode *> instantiatednodes = this->scope.instantiateChildren(&c); node->children.insert(node->children.end(), instantiatednodes.begin(), instantiatednodes.end()); - stack.pop(); + module_stack.pop_back(); return node; } |