-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CBA_fnc_(de)serializeNamespace (#609)
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_deserializeNamespace | ||
Description: | ||
Creates namespace containing all variables stored in a CBA hash. | ||
Parameters: | ||
_hash - a hash <ARRAY> | ||
_isGlobal - create a global namespace (optional, default: false) <BOOLEAN> | ||
Returns: | ||
_namespace - a namespace <LOCATION, OBJECT> | ||
Examples: | ||
(begin example) | ||
private _hash = profileNamespace getVariable "My_serializedNamespace"; | ||
My_namespace = [_hash] call CBA_fnc_deserializeNamespace; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(deserializeNamespace); | ||
|
||
params [["_hash", [], [[]]], ["_isGlobal", false, [false]]]; | ||
|
||
private _namespace = _isGlobal call CBA_fnc_createNamespace; | ||
|
||
if (_isGlobal) then { | ||
[_hash, { | ||
_namespace setVariable [_key, _value, true]; | ||
}] call CBA_fnc_hashEachPair; | ||
} else { | ||
[_hash, { | ||
_namespace setVariable [_key, _value]; | ||
}] call CBA_fnc_hashEachPair; | ||
}; | ||
|
||
_namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ---------------------------------------------------------------------------- | ||
Function: CBA_fnc_serializeNamespace | ||
Description: | ||
Creates CBA hash containing all variables stored in a namespace. | ||
Parameters: | ||
_namespace - a namespace <LOCATION, OBJECT> | ||
Returns: | ||
_hash - a hash <ARRAY> | ||
Examples: | ||
(begin example) | ||
private _hash = _namespace call CBA_fnc_serializeNamespace; | ||
profileNamespace setVariable ["My_serializedNamespace", _hash]; | ||
(end) | ||
Author: | ||
commy2 | ||
---------------------------------------------------------------------------- */ | ||
#include "script_component.hpp" | ||
SCRIPT(serializeNamespace); | ||
|
||
params [["_namespace", locationNull, [locationNull, objNull]]]; | ||
|
||
private _hash = [] call CBA_fnc_hashCreate; | ||
|
||
{ | ||
[_hash, _x, _namespace getVariable _x] call CBA_fnc_hashSet; | ||
} forEach allVariables _namespace; | ||
|
||
_hash |