Namespaces
zParserExtender also implements namespaces. Namespaces ensure that all symbols inside the namespace are unique.
Defining a namespace
To define a namespace the new keyword namespace
is used.
Namespace nesting
Namespaces can be nested for finer control. In case of injection, the namespace defined in META is applied to all code inside the script.
To go deeper into the namespaces you use the namespace operator :
. This code shows function with the same name within three different namespaces. The call in GameInit
is made from the global namespace.
Namespace traversal
To go up a namespace tree you use the namespace operator :
without specifying a namespace. Number of operators determines how many levels you go up.
Optional namespace specification
There are three cases where the namespace prefix is optional
Global namespace and Daedalus hooking
Namespace can not only be defined to an existing symbol but also to define new ones. Next code example shows how to implement a hook to a global instance.
ItAr_Pir_L_Addon
from the namespace zTestNamespace01
to a global namespace, you have to refer to the global namespace using the namespace operator :
. Since the function will be defined globally (as every symbol in ZenGin), it will be a part of the zTestNamespace01
which means that all functions will be local to this namespace.