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 '_thisArgs', '_thisId', '_thisType' and '_thisFnc' and to CBA events #375

Merged
merged 5 commits into from
Jun 13, 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
7 changes: 5 additions & 2 deletions addons/events/fnc_addEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Description:
Parameters:
_eventName - Type of event to handle. <STRING>
_eventFunc - Function to call when event is raised. <CODE>
_arguments - Arguments to pass to event handler. (optional) <Any>

Returns:
_eventId - Unique ID of the event handler (can be used with <CBA_fnc_removeEventHandler>).
Expand All @@ -22,7 +23,7 @@ Author:
#include "script_component.hpp"
SCRIPT(addEventHandler);

params [["_eventName", "", [""]], ["_eventFunc", nil, [{}]]];
params [["_eventName", "", [""]], ["_eventFunc", nil, [{}]], ["_arguments", []]];

{
if (_eventName isEqualTo "" || isNil "_eventFunc") exitWith {-1};
Expand All @@ -39,14 +40,16 @@ params [["_eventName", "", [""]], ["_eventFunc", nil, [{}]]];
GVAR(eventHashes) setVariable [_eventName, _eventHash];
};

private _internalId = _events pushBack _eventFunc;
private _eventData = [_eventFunc, _arguments];
private _internalId = _events pushBack _eventData;

// get last id
private _eventId = [_eventHash, "#lastId"] call CBA_fnc_hashGet;

// inc id
_eventId = _eventId + 1;

_eventData pushBack _eventId;
[_eventHash, "#lastId", _eventId] call CBA_fnc_hashSet;
[_eventHash, _eventId, _internalId] call CBA_fnc_hashSet;

Expand Down
4 changes: 3 additions & 1 deletion addons/events/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

#define CALL_EVENT(params,event) {\
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the macro argument "params" be renamed so as to not collide with the reserved word (command) params?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. That collided with the params command I added ...

if !(isNil "_x") then {\
params call _x;\
private _thisType = event;\
_x params ["_thisFnc", "_thisArgs", "_thisId"];\
params call _thisFnc;\
};\
} forEach (GVAR(eventNamespace) getVariable event)

Expand Down