diff options
author | Marius Kintel <marius@kintel.net> | 2013-10-04 22:13:26 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-10-04 22:13:26 (GMT) |
commit | b4e80581ca09068e07050a09802a0fc23fa6342b (patch) | |
tree | a0f6442ec2b34b37cd7ac7f88e11c86b8f07ffc9 /src/func.cc | |
parent | 793ee8eb8887be567a679a83fcaf3970ebf48d50 (diff) | |
parent | 400d28d753aa8af8de60a7f82851ffdc3cdae672 (diff) |
Merge branch 'bom-tree-std-stack' of git://github.com/steelman/openscad into steelman-bom-tree-std-stack
Conflicts:
src/module.cc
Diffstat (limited to 'src/func.cc')
-rw-r--r-- | src/func.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/func.cc b/src/func.cc index 20f487a..865a2b4 100644 --- a/src/func.cc +++ b/src/func.cc @@ -528,6 +528,29 @@ Value builtin_version_num(const Context *ctx, const EvalContext *evalctx) return Value(y * 10000 + m * 100 + d); } +Value builtin_parent_module(const Context *, const EvalContext *evalctx) +{ + int n; + double d; + int s = Module::stack_size(); + if (evalctx->numArgs() == 0) + d=1; // parent module + else if (evalctx->numArgs() == 1 && evalctx->getArgValue(0).type() == Value::NUMBER) + evalctx->getArgValue(0).getDouble(d); + else + return Value(); + n=trunc(d); + if (n < 0) { + PRINTB("WARNING: Negative parent module index (%d) not allowed", n); + return Value(); + } + if (n >= s) { + PRINTB("WARNING: Parent module index (%d) greater than the number of modules on the stack", n); + return Value(); + } + return Value(Module::stack_element(s - 1 - n)); +} + void register_builtin_functions() { Builtins::init("abs", new BuiltinFunction(&builtin_abs)); @@ -556,4 +579,5 @@ void register_builtin_functions() Builtins::init("search", new BuiltinFunction(&builtin_search)); Builtins::init("version", new BuiltinFunction(&builtin_version)); Builtins::init("version_num", new BuiltinFunction(&builtin_version_num)); + Builtins::init("parent_module", new BuiltinFunction(&builtin_parent_module)); } |