diff options
author | Marius Kintel <marius@kintel.net> | 2011-10-03 22:09:04 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2011-10-03 22:09:04 (GMT) |
commit | 2f239205a8f46cf00dfd461a72909867fa4aca80 (patch) | |
tree | 930bf143a8e341df817e321a7f891300a053b5aa | |
parent | 4432eb78aa5fc46a746893f8bdfe4f62f83e61a4 (diff) |
Redefined version() to return the version as a vector. Added version_num() to return a comparable number
-rw-r--r-- | RELEASE_NOTES | 3 | ||||
-rw-r--r-- | openscad.pro | 7 | ||||
-rw-r--r-- | src/func.cc | 22 | ||||
-rw-r--r-- | testdata/scad/minimal/allfunctions.scad | 1 |
4 files changed, 30 insertions, 3 deletions
diff --git a/RELEASE_NOTES b/RELEASE_NOTES index f8a10f0..9097721 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -10,7 +10,8 @@ o The color() statement now supports an alpha parameter, e.g. color(c=[1,0,0], a o The color() statement now supports specifying colors as strings, e.g. color("Red") o if() and else() can now take any value type as parameter. false, 0, empty string and empty vector or illegal value type will evaluate as false, everything else as true. o Strings can now be lexographically compared using the <, <=, >, >= operators -o The version() function will return the OpenSCAD version as a string, e.g. "2011.10" +o The version() function will return the OpenSCAD version as a vector, e.g. [2011, 09] +o The version_num() function will return the OpenSCAD version as a number, e.g. 20110923 Bugfixes: o square() crashed if any of the dimensions were zero diff --git a/openscad.pro b/openscad.pro index 271c34d..3a41800 100644 --- a/openscad.pro +++ b/openscad.pro @@ -13,6 +13,10 @@ win32 { } else { isEmpty(VERSION) VERSION = $$system(date "+%Y.%m.%d") } +VERSION_SPLIT=$$split(VERSION, ".") +VERSION_YEAR=$$member(VERSION_SPLIT, 0) +VERSION_MONTH=$$member(VERSION_SPLIT, 1) +VERSION_DAY=$$member(VERSION_SPLIT, 2) #configure lex / yacc win32 { @@ -31,7 +35,8 @@ win32 { INCLUDEPATH += $$(MPFRDIR) } -DEFINES += OPENSCAD_VERSION=$$VERSION +DEFINES += OPENSCAD_VERSION=$$VERSION OPENSCAD_YEAR=$$VERSION_YEAR OPENSCAD_MONTH=$$VERSION_MONTH +!isEmpty(VERSION_DAY): DEFINES += OPENSCAD_DAY=$$VERSION_DAY win32:DEFINES += _USE_MATH_DEFINES NOMINMAX _CRT_SECURE_NO_WARNINGS YY_NO_UNISTD_H #disable warning about too long decorated names diff --git a/src/func.cc b/src/func.cc index 964214f..b011a27 100644 --- a/src/func.cc +++ b/src/func.cc @@ -353,7 +353,26 @@ Value builtin_lookup(const Context *, const std::vector<std::string>&, const std Value builtin_version(const Context *, const std::vector<std::string>&, const std::vector<Value> &) { - return Value(std::string(QUOTED(OPENSCAD_VERSION))); + Value val; + val.type = Value::VECTOR; + val.append(new Value(double(OPENSCAD_YEAR))); + val.append(new Value(double(OPENSCAD_MONTH))); +#ifdef OPENSCAD_DAY + val.append(new Value(double(OPENSCAD_DAY))); +#endif + return val; +} + +Value builtin_version_num(const Context *ctx, const std::vector<std::string>& call_argnames, const std::vector<Value> &args) +{ + Value val = (args.size() == 0) ? builtin_version(ctx, call_argnames, args) : args[0]; + double y, m, d = 0; + if (!val.getv3(y, m, d)) { + if (!val.getv2(y, m)) { + return Value(); + } + } + return Value(y * 10000 + m * 100 + d); } void initialize_builtin_functions() @@ -381,6 +400,7 @@ void initialize_builtin_functions() builtin_functions["str"] = new BuiltinFunction(&builtin_str); builtin_functions["lookup"] = new BuiltinFunction(&builtin_lookup); builtin_functions["version"] = new BuiltinFunction(&builtin_version); + builtin_functions["version_num"] = new BuiltinFunction(&builtin_version_num); initialize_builtin_dxf_dim(); } diff --git a/testdata/scad/minimal/allfunctions.scad b/testdata/scad/minimal/allfunctions.scad index c33b43c..ef21a90 100644 --- a/testdata/scad/minimal/allfunctions.scad +++ b/testdata/scad/minimal/allfunctions.scad @@ -23,3 +23,4 @@ a = lookup(); a = dxf_dim(); a = dxf_cross(); a = version(); +a = version_num(); |