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

Conversation

Projects
None yet
4 participants
@654wak654
Copy link
Contributor

commented Oct 26, 2016

When merged this pull request will:

  • Add a logical RETDEF() macro
  • Check the function header for more
Add INV() and RETDEF() macros
INV() - math
RETDEF() - logic
Author:
654wak654
------------------------------------------- */
#define INV(var) var = (var) * -1

This comment has been minimized.

Copy link
@commy2

commy2 Oct 26, 2016

Contributor

var = -var
?

This comment has been minimized.

Copy link
@654wak654

654wak654 Oct 26, 2016

Author Contributor

That... Makes a lot of sense actually. Do you know what happens if _var is already negative?

This comment has been minimized.

Copy link
@jonpas

jonpas Oct 26, 2016

Member

Mathemetically -- == +.

Author:
654wak654
------------------------------------------- */
#define RETDEF(VARIABLE,DEFAULT_VALUE) if (isNil {VARIABLE}) then {DEFAULT_VALUE} else {VARIABLE}

This comment has been minimized.

Copy link
@commy2

commy2 Oct 26, 2016

Contributor

Should be encapsulated in parenthesis. Same for RETNIL(). Would make them safe to be used in longer expressions.

This comment has been minimized.

Copy link
@Dorbedo

Dorbedo Oct 26, 2016

Contributor

The following is faster:
#define RETDEF(VARIABLE,DEFAULT_VALUE) ([VARIABLE] param [0,DEFAULT_VALUE])

This comment has been minimized.

Copy link
@654wak654

654wak654 Oct 26, 2016

Author Contributor

It's shorter too, I like it.

Use param in RETX(), Use - in INV()
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])

This comment has been minimized.

Copy link
@commy2

commy2 Oct 26, 2016

Contributor

([VARIABLE] param [0])
since it's optional and defaults to nil anyway.

This comment has been minimized.

Copy link
@commy2

commy2 Oct 26, 2016

Contributor

Otherwise, maybe this is the fastest:

(if !(isNil {VARIABLE}) then {VARIABLE})

But I guess that depends on the expression of VARIABLE

@commy2

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2016

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

@654wak654

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2016

lgtm

@commy2

This comment has been minimized.

Copy link
Contributor

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@654wak654 654wak654 deleted the 654wak654:new-macros branch Oct 29, 2016

@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
You can’t perform that action at this time.