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));
This commit is contained in:
Sei Lisa 2016-11-18 00:18:22 +01:00
parent 0bd5c0881c
commit 9f03c468f7

View file

@ -364,8 +364,8 @@ but this will cause an error:
<p>This enables using many preprocessor tricks, like creating an <code>assert()</code> macro similar to that in C:</p>
<pre><code>#define assert(x) do { if (DEBUG &amp;&amp; !(x)) \
llOwnerSay("ASSERTION FAILED: " #x); } while (0)
<pre><code>#define assert(...) do { if (DEBUG) if (__VA_ARGS__) ; \
else llOwnerSay("ASSERTION FAILED: " #__VA_ARGS__); } while (0)
</code></pre>
<p>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.</p>