From 9f03c468f78a5cf7cc975098a1c416961cbc7437 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Fri, 18 Nov 2016 00:18:22 +0100 Subject: [PATCH] Fix example assert macro to make it more flexible The previous version only optimized away the condition if it was side-effect-free, which borders on inadmissible. Fixed. This new version also accepts any valid condition in LSL, not just an integer one but also float, key, list, string... so for example these are valid now: assert(my_key_var); assert([1, 2, 3]); assert(PI); assert(llSetPos(pos)); --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 462e4da..0777ff8 100644 --- a/index.html +++ b/index.html @@ -364,8 +364,8 @@ but this will cause an error:

This enables using many preprocessor tricks, like creating an assert() macro similar to that in C:

-
#define assert(x) do { if (DEBUG && !(x)) \
-  llOwnerSay("ASSERTION FAILED: " #x); } while (0)
+
#define assert(...) do { if (DEBUG) if (__VA_ARGS__) ; \
+  else llOwnerSay("ASSERTION FAILED: " #__VA_ARGS__); } while (0)
 

without worrying about the extra memory that it will take in production code once DEBUG is switched off, or about the loop taking up actual code memory.