Add Rhai book.

This commit is contained in:
Stephen Chung
2020-06-20 12:06:17 +08:00
parent 7e80d62df5
commit c7f1e12d6a
101 changed files with 3827 additions and 0 deletions

60
doc/src/about/features.md Normal file
View File

@@ -0,0 +1,60 @@
Features
========
{{#include ../links.md}}
Easy
----
* Easy-to-use language similar to JS+Rust with dynamic typing.
* Tight integration with native Rust [functions](/rust/functions.md) and [types](/rust/custom.md), including [getters/setters](/rust/getters-setters.md), [methods](/rust/custom.md) and [indexers](/rust/indexers.md).
* Freely pass Rust variables/constants into a script via an external [`Scope`].
* Easily [call a script-defined function](/engine/call-fn.md) from Rust.
* Very few additional dependencies (right now only [`num-traits`](https://crates.io/crates/num-traits/) to do checked arithmetic operations);
for [`no-std`] builds, a number of additional dependencies are pulled in to provide for functionalities that used to be in `std`.
Fast
----
* Fairly low compile-time overhead.
* Fairly efficient evaluation (1 million iterations in 0.25 sec on a single core, 2.3 GHz Linux VM).
* Scripts are [optimized](/engine/optimize.md) (useful for template-based machine-generated scripts) for repeated evaluations.
Dynamic
-------
* [Function overloading](/language/overload.md).
* [Operator overloading](/rust/operators.md).
* Organize code base with dynamically-loadable [modules].
Safe
----
* Relatively little `unsafe` code (yes there are some for performance reasons, and most `unsafe` code is limited to
one single source file, all with names starting with `"unsafe_"`).
Rugged
------
* Sand-boxed - the scripting [`Engine`], if declared immutable, cannot mutate the containing environment unless explicitly permitted (e.g. via a `RefCell`).
* Protected against malicious attacks (such as [stack-overflow](/safety/max-call-stack.md), [over-sized data](/safety/max-string-size.md), and [runaway scripts](/safety/max-operations.md) etc.) that may come from untrusted third-party user-land scripts.
* Track script evaluation [progress] and manually terminate a script run.
Flexible
--------
* Re-entrant scripting [`Engine`] can be made `Send + Sync` (via the [`sync`] feature).
* Support for [minimal builds] by excluding unneeded language [features].
* Supports [most build targets](targets.md) including `no-std` and [WASM].

View File

@@ -0,0 +1 @@
# What Rhai Doesn't Do

View File

@@ -0,0 +1,33 @@
What Rhai Doesn't Do
====================
{{#include ../links.md}}
Rhai's purpose is to provide a dynamic layer over Rust code, in the same spirit of _zero cost abstractions_.
It doesn't attempt to be a new language. For example:
* No classes. Well, Rust doesn't either. On the other hand...
* No traits... so it is also not Rust. Do your Rusty stuff in Rust.
* No structures/records - define your types in Rust instead; Rhai can seamlessly work with _any Rust type_.
There is, however, a built-in [object map] type which is adequate for most uses.
* No first-class functions - Code your functions in Rust instead, and register them with Rhai.
* No garbage collection - this should be expected, so...
* No closures - do your closure magic in Rust instead; [turn a Rhai scripted function into a Rust closure](/engine/call-fn.md).
* No byte-codes/JIT - Rhai has an AST-walking interpreter which will not win any speed races. The purpose of Rhai is not
to be extremely _fast_, but to make it as easy as possible to integrate with native Rust programs.
Due to this intended usage, Rhai deliberately keeps the language simple and small by omitting advanced language features
such as classes, inheritance, first-class functions, closures, concurrency, byte-codes, JIT etc.
Avoid the temptation to write full-fledge program logic entirely in Rhai - that use case is best fulfilled by
more complete languages such as JS or Lua.
Therefore, in actual practice, it is usually best to expose a Rust API into Rhai for scripts to call.
All your core functionalities should be in Rust.
This is similar to some dynamic languages where most of the core functionalities reside in a C/C++ standard library.

15
doc/src/about/related.md Normal file
View File

@@ -0,0 +1,15 @@
Related Resources
=================
{{#include ../links.md}}
Other online documentation resources for Rhai:
* [`DOCS.RS`](https://docs.rs/rhai)
Other cool projects to check out:
* [ChaiScript](http://chaiscript.com/) - A strong inspiration for Rhai. An embedded scripting language for C++ that I helped created many moons ago, now being led by my cousin.
* Check out the list of [scripting languages for Rust](https://github.com/rust-unofficial/awesome-rust#scripting) on [awesome-rust](https://github.com/rust-unofficial/awesome-rust)

12
doc/src/about/targets.md Normal file
View File

@@ -0,0 +1,12 @@
Supported Targets and Builds
===========================
{{#include ../links.md}}
The following targets and builds are support by Rhai:
* All common CPU targets for Windows, Linux and MacOS.
* [WASM]
* [`no-std`]