Refine docs.

This commit is contained in:
Stephen Chung
2020-08-07 18:40:31 +08:00
parent 0b21d80641
commit c86a979601
16 changed files with 128 additions and 53 deletions

View File

@@ -1,5 +1,5 @@
Singleton Command Objects
========================
Singleton Command Object
=======================
{{#include ../links.md}}
@@ -21,9 +21,11 @@ Usage Scenario
Key Concepts
------------
* Expose a Command type with an API.
* Expose a Command type with an API. The [`no_object`] feature must not be on.
* Since Rhai is _sand-boxed_, it cannot mutate the environment. To perform external actions via an API, the command object type must be wrapped in a `RefCell` (or `RwLock`/`Mutex` for [`sync`]) and shared to the [`Engine`].
* Leverage [function overloading] to simplify the API design.
* Since Rhai is _[sand-boxed]_, it cannot mutate the environment. To perform external actions via an API, the command object type must be wrapped in a `RefCell` (or `RwLock`/`Mutex` for [`sync`]) and shared to the [`Engine`].
* Load each command object into a custom [`Scope`] as constant variables.
@@ -33,6 +35,18 @@ Key Concepts
Implementation
--------------
There are two broad ways for Rhai to control an external system, both of which involve
wrapping the system in a shared, interior-mutated object.
This is the other way which involves directly exposing the data structures of the external system
as a name singleton object in the scripting space.
Use this when the API is complex and clearly object-based.
For a relatively simple API that is action-based and not object-based,
use the [Control Layer]({{rootUrl}}/patterns/control.md) pattern instead.
### Functional API
Assume the following command object type: