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.
namespacezTestNamespace01{funcvoidfunc01(){};};namespacezTestNamespace02{funcvoidfunc01(){};};namespacezTestNamespace03{namespacezTestNamespace04{funcvoidfunc01(){};};};funceventGameInit(){// In this case, the reference is from global namespace to zTestNamespacezTestNamespace01:func01();zTestNamespace02:func01();zTestNamespace03:zTestNamespace04:func01();};
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.
funcvoidfunc01(){Hlp_MessageBox("#1");};namespacezTestNamespace01{funcvoidfunc01(){Hlp_MessageBox("#2");};namespacezTestNamespace02{funcvoidfunc01(){Hlp_MessageBox("#3");};namespacezTestNamespace03{funcvoidfunc01(){Hlp_MessageBox("#4");};funceventGameInit(){:::func01();// Calls the function 3 levels up::func01();// Calls the function 2 levels up:func01();// Calls the function 1 level upfunc01();// Calls the function from the current namespace};};};};
Optional namespace specification
There are three cases where the namespace prefix is optional
funcvoidfunc01(){Hlp_MessageBox("#1");};namespacezTestNamespace01{funcvoidfunc01(){Hlp_MessageBox("#2");};namespacezTestNamespace02{funceventGameInit(){// Function call from the global namespacefunc01();};};};
META{using=zTestNamespace01;};namespacezTestNamespace01{funcvoidfunc01(){Hlp_MessageBox("#1");};};funceventGameInit(){// Calls the function with the namespace specified in the META blockfunc01();};
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.
namespacezTestNamespace01{conststringVar01="New instance name";// Hooking the global instanceinstance:ItAr_Pir_L_Addon(C_Item){ItAr_Pir_L_Addon_Old();name=Var01;};};
To hook an object, both signature and namespace has to match. It is syntactically allowed to hook an instance from a different space. Specify explicitly to which namespace the object will belong. This means that to hook 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.