-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RETDEF() Macro, Improve RETNIL(), fix IS_INTEGER() #537
Conversation
INV() - math RETDEF() - logic
Author: | ||
654wak654 | ||
------------------------------------------- */ | ||
#define INV(var) var = (var) * -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var = -var
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That... Makes a lot of sense actually. Do you know what happens if _var
is already negative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mathemetically --
== +
.
Author: | ||
654wak654 | ||
------------------------------------------- */ | ||
#define RETDEF(VARIABLE,DEFAULT_VALUE) if (isNil {VARIABLE}) then {DEFAULT_VALUE} else {VARIABLE} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be encapsulated in parenthesis. Same for RETNIL()
. Would make them safe to be used in longer expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following is faster:
#define RETDEF(VARIABLE,DEFAULT_VALUE) ([VARIABLE] param [0,DEFAULT_VALUE])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's shorter too, I like it.
Also encapsulated IS_INTEGER()
(end example) | ||
|
||
Author: | ||
Alef (see CBA issue #8514) | ||
------------------------------------------- */ | ||
#define RETNIL(VARIABLE) if (isNil{VARIABLE}) then {nil} else {VARIABLE} | ||
#define RETNIL(VARIABLE) ([VARIABLE] param [0,nil]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
([VARIABLE] param [0])
since it's optional and defaults to nil
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, maybe this is the fastest:
(if !(isNil {VARIABLE}) then {VARIABLE})
But I guess that depends on the expression of VARIABLE
lgtm, untested |
Q: |
It makes it obvious what operation is being done, but yes having a macro for a single char does sound excessive. Up to you. |
lgtm |
tested:
result:
works, merged 👍 |
When merged this pull request will: