By registering global properties with the script engine you can allow the scripts to inspect and/or modify variables within the application directly, without the need to write special functions to do this.
To register the property, you just need to call the RegisterGlobalProperty method, passing the declaration and a pointer to the property. Remember that the registered property must stay alive as long as its registration is valid in the engine.
Make sure you give the correct pointer to AngelScript. The pointer should be to value that the declaration refers to, i.e. if the declaration is an integer then the pointer should be to the integer value, if the declaration is an object handle then the pointer should be to the pointer to the object, etc. Unfortunately there is no way for AngelScript to validate that the pointer is correct, so if the wrong pointer is given, you will only detect it at runtime when seeing unexpected behaviours from the application.
It is also possible to expose properties through property accessors, which are a pair of functions with the prefixes 'get_' and 'set_' and the function decorator 'property' for getting and setting the property value. These functions should be registered with RegisterGlobalFunction. This is especially useful when the offset of the property cannot be determined, or if the type of the property is not registered in the script and some translation must occur, i.e. from char*
to string
.