Services
Some functionality, like code viewer actions can be accessed via global Services. The process of getting a service instance differs in plugins and scripts.
Plugins
Here getTool() is a protected method of the Plugin ancestor class.
Scripts
Here state is a predefined variable in the scripting context.