Add a section to the C++ intepreter intro about global singletons

Also minor fixes to the generated C++ global singleton docs.
This commit is contained in:
Simon Hausmann 2021-08-27 17:14:57 +02:00
parent 3212cda271
commit 54182ff54b
2 changed files with 15 additions and 6 deletions

View file

@ -96,10 +96,9 @@ private:
## Global Singletons
In `.60` files it is possible to declare [singletons that are globally available](markdown/langref.md#global-singletons).
It's possible to make these global singletons accessible to your C++ code, by exporting them and using the
`global()` getter function in the C++ class generated for your entry component. Each global singleton
creates a class that has getter/setter functions for properties and callbacks, similar to API that's
created for your `.60` component, as demonstrated in the previous section.
You can access them from to your C++ code by exporting them and using the `global()` getter function in the
C++ class generated for your entry component. Each global singleton creates a class that has getter/setter functions
for properties and callbacks, similar to API that's created for your `.60` component, as demonstrated in the previous section.
For example the following `.60` markup defines a global `Logic` singleton that's also exported:
@ -115,7 +114,7 @@ like this:
```cpp
auto app = SampleComponent::create();
// ...
app.global<Logic>().on_to_uppercase([](SharedString str) -> SharedString {
app->global<Logic>().on_to_uppercase([](SharedString str) -> SharedString {
std::string arg(str);
std::transform(arg.begin(), arg.end(), arg.begin(), toupper);
return SharedString(arg);