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

replace PUSH() Macro with pushback #247

Merged
merged 2 commits into from
Feb 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if !(isDedicated) then {
[GVAR(actionList), {
TRACE_3("Inside the code for the hashPair",(vehicle player),GVAR(actionIndexes), _value);
if (!isNil "_value" && typeName(_value) == "ARRAY") then {
PUSH(GVAR(actionIndexes), (vehicle player) addAction _value)
GVAR(actionIndexes) pushBack (vehicle player) addAction _value
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need safeguarding with
GVAR(actionIndexes) pushBack ((vehicle player) addAction _value) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

When in doubt its better to add it anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah. This is missing the brackets too.
Evaluations of binary commands are done from left to right:
GVAR(actionIndexes) pushBack (vehicle player) addAction _value
->
<index/number> addAction _value
->
Error Number expected object

The brackets around (vehicle player) on the other hand are optional.

Correct and minimalistic:
GVAR(actionIndexes) pushBack (vehicle player addAction _value)

I personally think that it's best to use as few brackets as possbile. Only exception would be
(unaryCommand _var1) binaryCommand _var2, so in the end exactly what killswitch proposed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think that it's best to use as few brackets as possbile

I know you do 😉.

Just to ring the opposite bell, I think it's usefull for the code to be as self-obvious as possible, so reviewers/maintainers don't have to wonder if a certain line is being interpreted correctly or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's usefull for the code to be as self-obvious as possible

True. But everyone reviewing SQF should know the basic principles. And too many brackets hurt readability.
That discussion doesn't belong here though. The line is currently wrong and errors out.

};
}] call CBA_fnc_hashEachPair;
};
Expand Down
5 changes: 4 additions & 1 deletion addons/common/fnc_createCenter.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ Author:
private ["_center"];
params ["_side"];
// TODO: Add _side if already a unit exists on this side ? by trying to create one or otherwise
if (_side in GVAR(centers)) then { _side } else { _center = createCenter _side; PUSH(GVAR(centers),_center); _center };
if (_side in GVAR(centers)) then { _side } else { _center = createCenter _side;
GVAR(centers) pushBack _center;
_center
};
2 changes: 1 addition & 1 deletion addons/common/fnc_getAlive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ switch (_typename) do {
_return = [];
{
if (alive _x) then {
PUSH(_return,_x);
_return pushBack _x;
}
} foreach _array;
_return
4 changes: 2 additions & 2 deletions addons/common/fnc_getFirer.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for "_mti" from 0 to (_tc-1) do {
_cfg = (__cfg select _mti);
if (isClass _cfg) then {
_entry = [_mtJ];
PUSH(_tp, _entry);
_tp pushBack _entry;

// Check SubTurrets
_st = _cfg >> "turrets";
Expand All @@ -53,7 +53,7 @@ for "_mti" from 0 to (_tc-1) do {
_stp = _st select _sti;
if (isClass _stp) then {
_entry = [_mtJ, _stJ];
PUSH(_tp, _entry);
_tp pushBack _entry;

INC(_stJ);
};
Expand Down
2 changes: 1 addition & 1 deletion addons/common/fnc_getGroupIndex.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _number = [];
// Format of player label is "<groupName>:<groupNumber> <playerName>"
for "_i" from (_groupLabelLen + 1) to ((count _labelArray) - 1) do {
if ((_labelArray select _i) == ASCII_SPACE) exitWith {};
PUSH(_number,_labelArray select _i);
_number pushBack _labelArray select _i;
Copy link
Contributor

Choose a reason for hiding this comment

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

_number pushBack (_labelArray select _i);

};

// Go back to the original varName.
Expand Down
2 changes: 1 addition & 1 deletion addons/common/fnc_getTurret.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (count _tp > 0) then {
_turs = [];
for "_i" from 0 to (count _turrets) - 1 do {
_y = _turrets select _i;
if (isClass(_y)) then { PUSH(_turs,_y) };
if (isClass(_y)) then { _turs pushBack _y };
};
if ((count _turs)-1 >= _x) then {
_path = (_turs select _x);
Expand Down
24 changes: 12 additions & 12 deletions addons/common/fnc_parseYAML.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ _raiseError =
_lastChar = _lastLine select ((count _lastLine) - 1);
_lastLine resize ((count _lastLine) - 1);

PUSH(_lastLine,ASCII_VERTICAL_BAR);
PUSH(_lastLine,ASCII_HASH);
PUSH(_lastLine,ASCII_VERTICAL_BAR);
PUSH(_lastLine,_lastChar);
_lastLine pushBack ASCII_VERTICAL_BAR;
_lastLine pushBack ASCII_HASH;
_lastLine pushBack ASCII_VERTICAL_BAR;
_lastLine pushBack _lastChar;

_pos = _pos + 1;
while { _pos < (count _yaml) } do {
_char = _yaml select _pos;

if (_char in [ASCII_YAML_COMMENT, ASCII_CR, ASCII_NEWLINE]) exitWith {};

PUSH(_lastLine,_char);
_lastLine pushBack _char;

_pos = _pos + 1;
};
Expand Down Expand Up @@ -114,9 +114,9 @@ _parse =
if (_char in _lineBreaks) then
{
_currentIndent = 0;
PUSH(_lines,[]);
_lines pushBack [];
} else {
PUSH(_lines select ((count _lines) - 1), _char);
_lines select ((count _lines) - 1) pushBack _char;
};

switch (_mode) do
Expand All @@ -142,11 +142,11 @@ _parse =
if (not _error) then
{
//TRACE_1("Added Array element",_value);
PUSH(_data,_value);
_data pushBack _value;
_mode = YAML_MODE_STRING;
};
} else {
PUSH(_value,_char);
_value pushBack _char;
};
};
case YAML_MODE_ASSOC_KEY:
Expand All @@ -166,7 +166,7 @@ _parse =
};
default
{
PUSH(_key,_char);
_key pushBack _char;
};
};
};
Expand Down Expand Up @@ -196,7 +196,7 @@ _parse =
_mode = YAML_MODE_STRING;
};
} else {
PUSH(_value,_char);
_value pushBack _char;
};
};
case YAML_MODE_STRING:
Expand Down Expand Up @@ -336,7 +336,7 @@ if (count _yaml > 0) then
{
if (not ((_yaml select ((count _yaml) - 1)) in _lineBreaks)) then
{
PUSH(_yaml,ASCII_NEWLINE);
_yaml pushBack ASCII_NEWLINE;
};
};

Expand Down
3 changes: 1 addition & 2 deletions addons/common/init_addons.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _addons = [];
for "_i" from 0 to (_c - 1) do {
_entry = _cfg select _i;
if (isClass _entry) then {
PUSH(_addons,configName _entry);
_addons pushBack configName _entry;
};
};

Expand All @@ -24,4 +24,3 @@ activateAddons _addons;
TRACE_1("Activated",count _addons);

CBA_common_addons = _addons;

18 changes: 9 additions & 9 deletions addons/diagnostic/fnc_debug.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ _ar2msg = {
_orig = _this;
_str = "[";
};
{ PUSH(_ar,toArray _x) } forEach _orig;
{ _ar pushBack toArray _x } forEach _orig;
_msg = [];
_total = 0; _i = 0;
{
Expand All @@ -58,14 +58,14 @@ _ar2msg = {
if (_i > 0) then { _str = _str + ", " };
_str = _str + toString(_x);
} else {
PUSH(_msg,_str);
_msg pushBack _str;
_total = _c;
_str = toString(_x);
};
_i = _i + 1;
} forEach _ar;
_str = _str + "]";
PUSH(_msg,_str);
_msg pushBack _str;
_msg
};

Expand All @@ -77,15 +77,15 @@ _str2msg = {
{
if (_i < 180) then
{
PUSH(_nar,_x);
_nar pushBack _x;
_i = _i + 1;
} else {
PUSH(_msg,toString(_nar));
_msg pushBack toString(_nar);
_nar = [_x];
_i = 1;
};
} forEach _ar;
if (count _nar > 0) then { PUSH(_msg,toString(_nar)) };
if (count _nar > 0) then { _msg pushBack toString(_nar) };
_msg
};

Expand All @@ -94,7 +94,7 @@ _format = {
_msg = [];
switch (typeName _this) do
{
case "ARRAY": { { { PUSH(_msg,_x) } forEach (_x call _str2msg) } forEach _this };
case "ARRAY": { { { _msg pushBack _x } forEach (_x call _str2msg) } forEach _this };
case "STRING": { _msg = _this call _str2msg };
default { _msg = format["%1", _this] call _str2msg };
};
Expand Down Expand Up @@ -123,10 +123,10 @@ if (_type select 2) exitWith
_msgAr = [];
switch (typeName _message) do
{
case "ARRAY": { _msgAr = [format["%3 (%2) %1 -", _component, [time, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime, [diag_tickTime, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime]]; { PUSH(_msgAr,_x) } forEach (_message call _ar2msg) };
case "ARRAY": { _msgAr = [format["%3 (%2) %1 -", _component, [time, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime, [diag_tickTime, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime]]; { _msgAr pushBack _x } forEach (_message call _ar2msg) };
default { _msgAr = (format["%4 (%3) %1 - %2", _component, _message, [time, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime, [diag_tickTime, "H:MM:SS.mmm"] call CBA_fnc_formatElapsedTime] call _format) };
};

if (_type select 0) then { if (SLX_XEH_MACHINE select 0) then { { ADDON globalChat _x } forEach _msgAr } };
if (_type select 1) then { { if (_x != "") then { diag_log text _x } } forEach _msgAr };
//PUSH(GVAR(debug),_msgAr); // TODO: Evaluate cleanup system?
//GVAR(debug) pushBack _msgAr; // TODO: Evaluate cleanup system?
2 changes: 1 addition & 1 deletion addons/diagnostic/fnc_log.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SCRIPT(log);
if (isNil "CBA_LOG_ARRAY") then { CBA_LOG_ARRAY = [] };
private ["_msg"];
_msg = [_this select 0, _this select 1, _this select 2, diag_frameNo, diag_tickTime, time]; // Save it here because we want to know when it was happening, not when it is outputted
PUSH(CBA_LOG_ARRAY,_msg);
CBA_LOG_ARRAY pushBack _msg;

if (isNil "CBA_LOG_VAR") then
{
Expand Down
13 changes: 6 additions & 7 deletions addons/diagnostic/fnc_perf_loop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// For usage outside CBA
#define QUOTE(A) #A
#define GVAR(A) my_##A
#define PUSH(A,B) A pushBack B
*/

// temp
Expand Down Expand Up @@ -64,7 +63,7 @@ FUNC(lag2) = {
_objects = [];
for "_i" from 0 to 100 do {
_logic = "LOGIC" createVehicleLocal [0, 0, 0];
PUSH(_objects,_logic);
_objects pushBack _logic;
};
};

Expand Down Expand Up @@ -122,17 +121,17 @@ SLX_XEH_STR spawn {
waitUntil {time > _nextTime};
_ar = GVAR(ar); GVAR(ar) = [];
_log = ["Current", DEFAULT_VALUES];
PUSH(GVAR(logs),_log);
GVAR(logs) pushBack _log;
{
// TODO: Also compare the delta between the previous few entries?
_a = _x select 0; _b = _x select 1;
_deltaTick = (_b select 0) - (_a select 0);
_deltaTime = (_b select 1) - (_a select 1);
_log = ["Delta", _a, _b, _deltaTick, _deltaTime];
_do = false;
if (_deltaTime > _limit) then { _do = true; if (_deltaTime > _high) then { PUSH(_log,"WARNING: Large deltaTime"); PUSH(_log,_deltaTime) } };
if (_deltaTick > _limit) then { _do = true; if (_deltaTick > _high) then { PUSH(_log,"WARNING: Large deltaTick"); PUSH(_log,_deltaTick) } };
if (_do) then { PUSH(GVAR(logs),_log) };
if (_deltaTime > _limit) then { _do = true; if (_deltaTime > _high) then { _log pushBack "WARNING: Large deltaTime"; _log pushBack _deltaTime } };
if (_deltaTick > _limit) then { _do = true; if (_deltaTick > _high) then { _log pushBack "WARNING: Large deltaTick"; _log pushBack _deltaTick } };
if (_do) then { GVAR(logs) pushBack _log };
} forEach _ar;
if (GVAR(interactive)) then {
// Output at each iteration
Expand All @@ -154,7 +153,7 @@ while {GVAR(log)} do {
sleep DELAY;
[] call _create;
_entry pushBack [DEFAULT_VALUES];
PUSH(GVAR(ar),_entry);
GVAR(ar) pushBack _entry;
};

GVAR(ar) = [];
Expand Down
2 changes: 1 addition & 1 deletion addons/events/fnc_addEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (isNil "_handlers") exitwith {
0;
};
// Handlers already recorded, so add another one.
_handlerIndex = PUSH(_handlers,_handler);
_handlerIndex = _handlers pushBack _handler;
TRACE_2("Added",_eventType,_handlerIndex);

_handlerIndex;
2 changes: 1 addition & 1 deletion addons/events/fnc_addKeyHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ _handlers = [GVAR(keyhandler_hash), _type] call CBA_fnc_hashGet;
if (_key > count _handlers) then {_handlers resize(_key + 1)};
_ar = _handlers select _key;
if (isNil"_ar")then{_ar=[]};
PUSH(_ar,_hashKey);
_ar pushBack _hashKey;
_handlers set [_key, _ar];

_hashKey;
2 changes: 1 addition & 1 deletion addons/events/fnc_addLocalEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (isNil "_handlers") then {
} else {
// Handlers already recorded, so add another one.
_handlerIndex = count _handlers;
PUSH(_handlers,_handler);
_handlers pushBack _handler;
};

TRACE_2("Added",_eventType,_handlerIndex);
Expand Down
2 changes: 1 addition & 1 deletion addons/events/fnc_changeKeyHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (_exit) exitWith { false };
if(_key>(count _handlers))then{_handlers resize(_key+1);};
_ar = _handlers select _key;
if(isNil"_ar")then{_ar=[]};
PUSH(_ar,_hashKey);
_ar pushBack _hashKey;
_handlers set [_key, _ar];

// Update keydata
Expand Down
12 changes: 6 additions & 6 deletions addons/events/fnc_keyHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if(_type == "keydown") then {
for "_i" from 0 to 2 do { if (((_settings select _i) && {!(_keyData select (_i + 2))}) || {(!(_settings select _i) && {(_keyData select (_i + 2))})}) exitWith { _valid = false } };
if (_valid) then {
#ifdef DEBUG_MODE_FULL
PUSH(_ar,_code);
_ar pushBack _code;
#endif

_holdKey = _data select 3;
Expand Down Expand Up @@ -123,10 +123,10 @@ if(_type == "keydown") then {
for "_i" from 0 to 2 do { if (((_settings select _i) && {!(_keyData select (_i + 2))}) || {(!(_settings select _i) && {(_keyData select (_i + 2))})}) exitWith { _valid = false } };
if (_valid) then {
#ifdef DEBUG_MODE_FULL
PUSH(_ar,_code);
_ar pushBack _code;
#endif

PUSH(GVAR(keyUpDownList), _x);
GVAR(keyUpDownList) pushBack _x;
};
};
} forEach _myHandlers;
Expand Down Expand Up @@ -182,13 +182,13 @@ if(_type == "keydown") then {
_result = false;
};
};
PUSH(_remHandlers, _x);
_remHandlers pushBack _x;
// If any handler says that it has completely _handled_ the keypress,
// then don't allow other handlers to be tried at all.
if (_result) then { PUSH(_ignoredUpKeys, _key); };
if (_result) then { _ignoredUpKeys pushBack _key; };
};
} else {
PUSH(_remHandlers, _x);
_remHandlers pushBack _x;
};

};
Expand Down
4 changes: 2 additions & 2 deletions addons/hashes/fnc_hashSet.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ if (_index >= 0) then
// Ignore values that are the same as the default.
if (not _isDefault) then
{
PUSH(_hash select HASH_KEYS,_key);
PUSH(_hash select HASH_VALUES,_value);
_hash select HASH_KEYS pushBack _key;
_hash select HASH_VALUES pushBack _value;
};
};
TRACE_1("",_hash);
Expand Down
2 changes: 1 addition & 1 deletion addons/help/XEH_preClientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ FUNC(readConfig) = {
FUNC(process) = {
params ["_h1","_h2","_h3"];
_ar = [];
[_h1, {_entry = format["%1, v%2, (%3)<br/>Author: %4", _key, [_h3, _key] call (uiNamespace getVariable "CBA_fnc_hashGet"), [_h2, _key] call (uiNamespace getVariable "CBA_fnc_hashGet"), _value joinString ", "]; PUSH(_ar,_entry) }] call (uiNamespace getVariable "CBA_fnc_hashEachPair");
[_h1, {_entry = format["%1, v%2, (%3)<br/>Author: %4", _key, [_h3, _key] call (uiNamespace getVariable "CBA_fnc_hashGet"), [_h2, _key] call (uiNamespace getVariable "CBA_fnc_hashGet"), _value joinString ", "]; _ar pushBack _entry }] call (uiNamespace getVariable "CBA_fnc_hashEachPair");
_ar joinString "<br/><br/>";
};

Expand Down
Loading