Skip to content
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

Merged
merged 4 commits into from
Oct 29, 2016
Merged

Add RETDEF() Macro, Improve RETNIL(), fix IS_INTEGER() #537

merged 4 commits into from
Oct 29, 2016

Conversation

654wak654
Copy link
Contributor

@654wak654 654wak654 commented Oct 26, 2016

When merged this pull request will:

  • Add a logical RETDEF() macro
  • Check the function header for more

INV() - math
RETDEF() - logic
Author:
654wak654
------------------------------------------- */
#define INV(var) var = (var) * -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var = -var
?

Copy link
Contributor Author

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?

Copy link
Member

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}
Copy link
Contributor

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.

Copy link
Contributor

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])

Copy link
Contributor Author

@654wak654 654wak654 Oct 26, 2016

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])
Copy link
Contributor

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.

Copy link
Contributor

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

@commy2
Copy link
Contributor

commy2 commented Oct 26, 2016

lgtm, untested

@commy2 commy2 added the Feature label Oct 26, 2016
@commy2 commy2 added this to the 3.2 milestone Oct 26, 2016
@commy2 commy2 self-assigned this Oct 26, 2016
@commy2
Copy link
Contributor

commy2 commented Oct 26, 2016

Q:
Do we need INV(var) when it's just - var? I don't see the benefit tbf.

@654wak654
Copy link
Contributor Author

654wak654 commented Oct 26, 2016

It makes it obvious what operation is being done, but yes having a macro for a single char does sound excessive. Up to you.

@654wak654 654wak654 changed the title Add INV() and RETDEF() Macros Add RETDEF() Macro Oct 26, 2016
@commy2 commy2 changed the title Add RETDEF() Macro Add RETDEF() Macro, Improve RETNIL(), fix IS_INTEGER() Oct 26, 2016
@commy2
Copy link
Contributor

commy2 commented Oct 26, 2016

lgtm

@commy2
Copy link
Contributor

commy2 commented Oct 29, 2016

tested:

private _banana = 127;
diag_log RETNIL(_banana);
diag_log RETDEF(_banana,-1);
diag_log RETDEF(_potato,-1);

result:

13:47:31 127
13:47:31 127
13:47:31 -1

works, merged 👍
thanks for the contribution : )

@commy2 commy2 merged commit 70336ff into CBATeam:master Oct 29, 2016
@654wak654 654wak654 deleted the new-macros branch October 29, 2016 12:11
@commy2 commy2 modified the milestones: 3.1.2, 3.2 Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants