Last active
July 4, 2016 17:12
-
-
Save commy2/e369cbfc0a44960b6c10108c9638ad3d to your computer and use it in GitHub Desktop.
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
/* ------------------------------------------- | |
Macro: NS_NULL | |
Description: | |
Returns a undefined (null) CBA namespace. | |
Parameters: | |
None | |
Example: | |
(begin example) | |
isNull NS_NULL // true | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_SYS_TYPE "FakeTown" | |
#define NS_SYS_GTYPE "Building" | |
#define NS_SYS_POS [-10000,-10000,0] | |
#define NS_SYS_NULL locationNull | |
#define NS_NULL objNull | |
/* ------------------------------------------- | |
Macro: NS_ALL | |
Description: | |
Returns all defined CBA namespaces. | |
Parameters: | |
None | |
Example: | |
(begin example) | |
count NS_ALL // 7 | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_ALL (nearestLocations [NS_SYS_POS, [NS_SYS_TYPE], 1] + nearestObjects [NS_SYS_POS, [NS_SYS_GTYPE], 1]) | |
/* ------------------------------------------- | |
Macro: NS_ISGLOBAL() | |
Description: | |
Returns if a CBA namespace exists on all machines. | |
Parameters: | |
0: Namespace | |
Example: | |
(begin example) | |
NS_ISGLOBAL(NS_NULL) // false | |
NS_ISGLOBAL(myPublicNamespace) // true | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_SYS_NS(namespace) ([if (isNil 'namespace') then [{nil}, {namespace}]] param [0, NS_NULL, [NS_NULL, NS_SYS_NULL]]) | |
#define NS_ISGLOBAL(namespace) !(NS_SYS_NS(namespace) isEqualType NS_SYS_NULL) | |
/* ------------------------------------------- | |
Macro: NS_DELETE() | |
Description: | |
Deletes a CBA namespace. | |
Parameters: | |
0: Namespace | |
Example: | |
(begin example) | |
NS_DELETE(myNamespace); | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_DELETE(namespace) (if (NS_ISGLOBAL(namespace)) then [{deleteVehicle NS_SYS_NS(namespace)}, {deleteLocation NS_SYS_NS(namespace)}]) | |
/* ------------------------------------------- | |
Macro: NS_CREATE() | |
Description: | |
Creates a local CBA namespace. | |
Parameters: | |
0: Namespace | |
Example: | |
(begin example) | |
NS_CREATE(myLocalNamespace); | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_SYS_INIT createLocation [NS_SYS_TYPE, NS_SYS_POS, 0, 0] | |
#define NS_CREATE(namespace) if (!isNull NS_SYS_NS(namespace)) then {NS_DELETE(namespace)}; namespace = NS_SYS_INIT | |
/* ------------------------------------------- | |
Macro: NS_CREATE_GLOBAL() | |
Description: | |
Creates a global (public) CBA namespace. | |
Parameters: | |
0: Namespace | |
Example: | |
(begin example) | |
NS_CREATE_GLOBAL(myPublicNamespace); | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_SYS_GINIT createVehicle [NS_SYS_GTYPE, NS_SYS_POS, [], 0, "NONE"] | |
#define NS_CREATE_GLOBAL(namespace) if (!isNull NS_SYS_NS(namespace)) then {NS_DELETE(namespace)}; namespace = NS_SYS_GINIT; publicVariable 'namespace' | |
/* ------------------------------------------- | |
Macro: NS_SET() | |
Description: | |
Sets a value of a key in a CBA namespace. | |
Parameters: | |
0: Namespace | |
1: Key <STRING> | |
2: Value <ANY> | |
Example: | |
(begin example) | |
NS_SET(myNamespace,_classname,true); | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_SET(namespace,var,value) (if (NS_ISGLOBAL(namespace)) then [{NS_SYS_NS(namespace) setVariable [var, value, true]}, {NS_SYS_NS(namespace) setVariable [var, value]}]) | |
/* ------------------------------------------- | |
Macro: NS_GET() | |
Description: | |
Reports the value of a key in a CBA namespace. | |
Parameters: | |
0: Namespace | |
1: Key <STRING> | |
Example: | |
(begin example) | |
NS_GET(myNamespace,_classname) | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_GET(namespace,var) (NS_SYS_NS(namespace) getVariable var) | |
/* ------------------------------------------- | |
Macro: NS_DGET() | |
Description: | |
Reports the value of a key in a CBA namespace. If undefined, the default value is used. | |
Parameters: | |
0: Namespace | |
1: Key <STRING> | |
2: Default value <ANY> | |
Example: | |
(begin example) | |
NS_DGET(myNamespace,_classname,false) | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_DGET(namespace,var,default) ([NS_GET(namespace,var)] param [0, default]) | |
/* ------------------------------------------- | |
Macro: NS_ISNIL() | |
Description: | |
Reports if a key has a definied value in a CBA namespace. | |
Parameters: | |
0: Namespace | |
1: Key <STRING> | |
Example: | |
(begin example) | |
NS_ISNIL(myNamespace,"undefined") // true | |
(end) | |
Author: | |
commy2 | |
------------------------------------------- */ | |
#define NS_ISNIL(namespace,var) isNil {NS_GET(namespace,var)} | |
/* ------------------------------------------- | |
Additional commands supported by CBA namespaces: | |
isNull namespace, allVariables namespace | |
------------------------------------------- */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment