From e2918e7f059e31c047ddfa9c79d84b6301ae3528 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 26 Jul 2014 23:50:49 +0200 Subject: [PATCH] Add constant NULL_KEY and function cond(). --- lslopt/lslbasefuncs.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index 7328e45..3e5109e 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -43,6 +43,7 @@ b64_re = re.compile(ur'^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2,3})?') ZERO_VECTOR = Vector((0.0, 0.0, 0.0)) ZERO_ROTATION = Quaternion((0.0, 0.0, 0.0, 1.0)) +NULL_KEY = u'00000000-0000-0000-0000-000000000000' Infinity = float('inf') NaN = float('nan') @@ -656,6 +657,19 @@ def less(a, b): return int(ff(a) < ff(b)) raise ELSLTypeMismatch +def cond(x): + """Test whether x evaluates to True in a condition (if, while, for, ...)""" + tx = type(x) + if tx == Key: + if x == NULL_KEY or len(x) != 36: + return False + return bool(key_re.match(x)) + if tx == Vector: + return bool(compare(x, ZERO_VECTOR, Eq=False)) + if tx == Quaternion: + return bool(compare(x, ZERO_ROTATION, Eq=False)) + return bool(x) # works fine for int, float, string, list + def isinteger(x): return type(x) == int @@ -966,7 +980,7 @@ def llList2Key(lst, pos): except IndexError: pass if lslcommon.LSO: - return Key(u'00000000-0000-0000-0000-000000000000') # NULL_KEY + return Key(NULL_KEY) return Key(u'') def llList2List(lst, start, end):