You can define local functions in structures, providing a convenient mechanism for packaging a set of related functions and avoiding possible name conflicts when many global functions are defined, possibly by several separate scripts.
Local functions declared in a structure definition can make references to the member data variables defined in the structure, such that when that member function in some instance of the structure is called, the references access the members of that instance. This allows you to initialize and maintain data structures for the structure functions within the structure itself. An example of including functions that use members of the structure is shown in the following script.
In this script, the structure has 3 data members and 6 function members. Note the references to the structure data members in the generateRV() function. In line 30, an instance of the RndVals structure is created and stored in variable MyRandomVals. In line 31, the setSeed() function in the structure instance is called, which initializes the random seed variable by storing the specified value in data member seedVal in the structure instance. In line 32, the generateRV() function in the structure instance is called, which initializes the random number using the seed value specified by setSeed(), sets up and stores an array of random numbers in data member RndVals, updates data member ptr, and then returns the random number array.
Local functions defined in structures are not stored in every instance of the structure. The local function is stored once in the structure definition and references to them in the instances refer to their definitions in the structure definition.