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

DirectCall - prevent problems with exitWith #690

Merged
merged 2 commits into from
Jun 3, 2017
Merged

Conversation

PabstMirror
Copy link
Contributor

Fixes #689

@PabstMirror PabstMirror added this to the 3.4 milestone Jun 3, 2017
@PabstMirror PabstMirror requested a review from commy2 June 3, 2017 14:56
@@ -27,7 +27,8 @@ params [["_CBA_code", {}, [{}]], ["_this", []]];
private "_CBA_return";

isNil {
_CBA_return = [_x] apply _CBA_code select 0;
// Wrap the _CBA_code in an extra call block to prevent problems with exitWith and apply
_CBA_return = ([nil] apply {call _CBA_code}) select 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This would mean that the _x variable is overwritten.

Copy link
Contributor Author

@PabstMirror PabstMirror Jun 3, 2017

Choose a reason for hiding this comment

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

_x = 5; 
x3 = [{_x = 4; systemChat str _x; }, 3] call cba_fnc_directCall;
systemChat str _x;

prints 4, 5.
I think the _x is privated from the apply, not sure?

@commy2
Copy link
Contributor

commy2 commented Jun 3, 2017

I think it should just be:

- _CBA_return = [_x] apply _CBA_code select 0;
+ _CBA_return = [_x] apply _CBA_code param [0];

@PabstMirror
Copy link
Contributor Author

That would fail if something returns an array:

_code = {num = random 1; if (num < 0.5) exitWith {[true, num]}; [false, num]};

[false,0.914843]
true

@commy2
Copy link
Contributor

commy2 commented Jun 3, 2017

Then I think your solution is best. But with [_x] and not [nil].

@commy2 commy2 added the Bug Fix label Jun 3, 2017
@commy2 commy2 merged commit b9142b6 into master Jun 3, 2017
@commy2 commy2 deleted the directCallWraper branch June 3, 2017 18:58
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

2 participants