mirror of https://github.com/vitalif/openscad
Integrate feature registry with functions.
In case a function is attached to a disabled feature, the function lookup will give a warning message and ignore that (builtin) function.vector-concat
parent
7f36599073
commit
09f8e80a7d
|
@ -3,13 +3,21 @@
|
|||
|
||||
#include "value.h"
|
||||
#include "typedefs.h"
|
||||
#include "feature.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class AbstractFunction
|
||||
{
|
||||
private:
|
||||
const Feature *feature;
|
||||
public:
|
||||
AbstractFunction() : feature(NULL) {}
|
||||
AbstractFunction(const Feature& feature) : feature(&feature) {}
|
||||
virtual ~AbstractFunction();
|
||||
virtual bool is_enabled() const { return (feature == NULL) || feature->is_enabled(); };
|
||||
virtual Value evaluate(const class Context *ctx, const class EvalContext *evalctx) const;
|
||||
virtual std::string dump(const std::string &indent, const std::string &name) const;
|
||||
};
|
||||
|
@ -21,6 +29,7 @@ public:
|
|||
eval_func_t eval_func;
|
||||
|
||||
BuiltinFunction(eval_func_t f) : eval_func(f) { }
|
||||
BuiltinFunction(eval_func_t f, const Feature& feature) : AbstractFunction(feature), eval_func(f) { }
|
||||
virtual ~BuiltinFunction();
|
||||
|
||||
virtual Value evaluate(const Context *ctx, const EvalContext *evalctx) const;
|
||||
|
|
|
@ -95,7 +95,12 @@ void ModuleContext::registerBuiltin()
|
|||
const AbstractFunction *ModuleContext::findLocalFunction(const std::string &name) const
|
||||
{
|
||||
if (this->functions_p && this->functions_p->find(name) != this->functions_p->end()) {
|
||||
return this->functions_p->find(name)->second;
|
||||
AbstractFunction *f = this->functions_p->find(name)->second;
|
||||
if (!f->is_enabled()) {
|
||||
PRINTB("WARNING: Experimental builtin function '%s' is not enabled.", name);
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue