Add shared and take to keywords list.

This commit is contained in:
Stephen Chung 2020-07-31 17:07:09 +08:00
parent df8587ac91
commit a35155b3e9
5 changed files with 52 additions and 47 deletions

View File

@ -3,35 +3,37 @@ Keywords List
{{#include ../links.md}} {{#include ../links.md}}
| Keyword | Description | Inactive under | | Keyword | Description | Inactive under | Overloadable |
| :-------------------: | ---------------------------------------- | :-------------: | | :-------------------: | ---------------------------------------- | :-------------: | :----------: |
| `true` | Boolean true literal | | | `true` | Boolean true literal | | No |
| `false` | Boolean false literal | | | `false` | Boolean false literal | | No |
| `let` | Variable declaration | | | `let` | Variable declaration | | No |
| `const` | Constant declaration | | | `const` | Constant declaration | | No |
| `if` | If statement | | | `shared` | Share value | [`no_shared`] | No |
| `else` | else block of if statement | | | `take` | Un-share value | [`no_shared`] | No |
| `while` | While loop | | | `if` | If statement | | No |
| `loop` | Infinite loop | | | `else` | else block of if statement | | No |
| `for` | For loop | | | `while` | While loop | | No |
| `in` | Containment test, part of for loop | | | `loop` | Infinite loop | | No |
| `continue` | Continue a loop at the next iteration | | | `for` | For loop | | No |
| `break` | Loop breaking | | | `in` | Containment test, part of for loop | | No |
| `return` | Return value | | | `continue` | Continue a loop at the next iteration | | No |
| `throw` | Throw exception | | | `break` | Loop breaking | | No |
| `import` | Import module | [`no_module`] | | `return` | Return value | | No |
| `export` | Export variable | [`no_module`] | | `throw` | Throw exception | | No |
| `as` | Alias for variable export | [`no_module`] | | `import` | Import module | [`no_module`] | No |
| `private` | Mark function private | [`no_function`] | | `export` | Export variable | [`no_module`] | No |
| `fn` (lower-case `f`) | Function definition | [`no_function`] | | `as` | Alias for variable export | [`no_module`] | No |
| `Fn` (capital `F`) | Function to create a [function pointer] | | | `private` | Mark function private | [`no_function`] | No |
| `call` | Call a [function pointer] | | | `fn` (lower-case `f`) | Function definition | [`no_function`] | No |
| `curry` | Curry a [function pointer] | | | `Fn` (capital `F`) | Function to create a [function pointer] | | Yes |
| `this` | Reference to base object for method call | [`no_function`] | | `call` | Call a [function pointer] | | No |
| `type_of` | Get type name of value | | | `curry` | Curry a [function pointer] | | No |
| `print` | Print value | | | `this` | Reference to base object for method call | [`no_function`] | No |
| `debug` | Print value in debug format | | | `type_of` | Get type name of value | | Yes |
| `eval` | Evaluate script | | | `print` | Print value | | Yes |
| `debug` | Print value in debug format | | Yes |
| `eval` | Evaluate script | | Yes |
Reserved Keywords Reserved Keywords
@ -59,7 +61,6 @@ Reserved Keywords
| `package` | Package | | `package` | Package |
| `spawn` | Threading | | `spawn` | Threading |
| `go` | Threading | | `go` | Threading |
| `shared` | Threading |
| `await` | Async | | `await` | Async |
| `async` | Async | | `async` | Async |
| `sync` | Async | | `sync` | Async |

View File

@ -5,21 +5,22 @@ Keywords
The following are reserved keywords in Rhai: The following are reserved keywords in Rhai:
| Active keywords | Reserved keywords | Usage | Inactive under feature | | Active keywords | Reserved keywords | Usage | Inactive under feature |
| ------------------------------------------------- | ---------------------------------------------------------- | --------------------- | :--------------------: | | ------------------------------------------------- | ------------------------------------------------ | --------------------- | :--------------------: |
| `true`, `false` | | Boolean constants | | | `true`, `false` | | Boolean constants | |
| `let`, `const` | `var`, `static` | Variable declarations | | | `let`, `const` | `var`, `static` | Variable declarations | |
| `if`, `else` | `then`, `goto`, `exit` | Control flow | | | `shared`, `take` | | Shared values | [`no_shared`] |
| | `switch`, `match`, `case` | Matching | | | `if`, `else` | `then`, `goto`, `exit` | Control flow | |
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | Looping | | | | `switch`, `match`, `case` | Matching | |
| `fn`, `private` | `public`, `new` | Functions | [`no_function`] | | `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | Looping | |
| `return` | | Return values | | | `fn`, `private` | `public`, `new` | Functions | [`no_function`] |
| `throw` | `try`, `catch` | Throw exceptions | | | `return` | | Return values | |
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | Modules/packages | [`no_module`] | | `throw` | `try`, `catch` | Throw exceptions | |
| `Fn`, `call`, `curry` | | Function pointers | | | `import`, `export`, `as` | `use`, `with`, `module`, `package` | Modules/packages | [`no_module`] |
| | `spawn`, `go`, `shared`, `sync`, `async`, `await`, `yield` | Threading/async | | | `Fn`, `call`, `curry` | | Function pointers | |
| `type_of`, `print`, `debug`, `eval` | | Special functions | | | | `spawn`, `go`, `sync`, `async`, `await`, `yield` | Threading/async | |
| | `default`, `void`, `null`, `nil` | Special values | | | `type_of`, `print`, `debug`, `eval` | | Special functions | |
| | `default`, `void`, `null`, `nil` | Special values | |
Keywords cannot become the name of a [function] or [variable], even when they are disabled. Keywords cannot become the name of a [function] or [variable], even when they are disabled.

View File

@ -14,9 +14,10 @@ The following primitive types are supported natively:
| **Immutable Unicode [string]** | `rhai::ImmutableString` (implemented as `Rc<String>` or `Arc<String>`) | `"string"` | `"hello"` etc. | | **Immutable Unicode [string]** | `rhai::ImmutableString` (implemented as `Rc<String>` or `Arc<String>`) | `"string"` | `"hello"` etc. |
| **[`Array`]** (disabled with [`no_index`]) | `rhai::Array` | `"array"` | `"[ ?, ?, ? ]"` | | **[`Array`]** (disabled with [`no_index`]) | `rhai::Array` | `"array"` | `"[ ?, ?, ? ]"` |
| **[Object map]** (disabled with [`no_object`]) | `rhai::Map` | `"map"` | `"#{ "a": 1, "b": 2 }"` | | **[Object map]** (disabled with [`no_object`]) | `rhai::Map` | `"map"` | `"#{ "a": 1, "b": 2 }"` |
| **[Timestamp]** (implemented in the [`BasicTimePackage`][packages], disabled with [`no_std`]) | `std::time::Instant` ([`instant::Instant`] if [WASM] build) | `"timestamp"` | _not supported_ | | **[Timestamp]** (implemented in the [`BasicTimePackage`][packages], disabled with [`no_std`]) | `std::time::Instant` ([`instant::Instant`] if [WASM] build) | `"timestamp"` | `"<timestamp>"` |
| **[Function pointer]** | `rhai::FnPtr` | `Fn` | `"Fn(foo)"` | | **[Function pointer]** | `rhai::FnPtr` | `Fn` | `"Fn(foo)"` |
| **[`Dynamic`] value** (i.e. can be anything) | `rhai::Dynamic` | _the actual type_ | _actual value_ | | **[`Dynamic`] value** (i.e. can be anything) | `rhai::Dynamic` | _the actual type_ | _actual value_ |
| **Shared value** (a reference-counted, shared [`Dynamic`] value) | | _the actual type_ | _actual value_ |
| **System integer** (current configuration) | `rhai::INT` (`i32` or `i64`) | `"i32"` or `"i64"` | `"42"`, `"123"` etc. | | **System integer** (current configuration) | `rhai::INT` (`i32` or `i64`) | `"i32"` or `"i64"` | `"42"`, `"123"` etc. |
| **System floating-point** (current configuration, disabled with [`no_float`]) | `rhai::FLOAT` (`f32` or `f64`) | `"f32"` or `"f64"` | `"123.456"` etc. | | **System floating-point** (current configuration, disabled with [`no_float`]) | `rhai::FLOAT` (`f32` or `f64`) | `"f32"` or `"f64"` | `"123.456"` etc. |
| **Nothing/void/nil/null/Unit** (or whatever it is called) | `()` | `"()"` | `""` _(empty string)_ | | **Nothing/void/nil/null/Unit** (or whatever it is called) | `()` | `"()"` | `""` _(empty string)_ |

View File

@ -10,6 +10,7 @@
[`no_function`]: {{rootUrl}}/start/features.md [`no_function`]: {{rootUrl}}/start/features.md
[`no_module`]: {{rootUrl}}/start/features.md [`no_module`]: {{rootUrl}}/start/features.md
[`no_capture`]: {{rootUrl}}/start/features.md [`no_capture`]: {{rootUrl}}/start/features.md
[`no_shared`]: {{rootUrl}}/start/features.md
[`no_std`]: {{rootUrl}}/start/features.md [`no_std`]: {{rootUrl}}/start/features.md
[`no-std`]: {{rootUrl}}/start/features.md [`no-std`]: {{rootUrl}}/start/features.md
[`internals`]: {{rootUrl}}/start/features.md [`internals`]: {{rootUrl}}/start/features.md

View File

@ -24,7 +24,8 @@ more control over what a script can (or cannot) do.
| `no_function` | Disable script-defined [functions]. | | `no_function` | Disable script-defined [functions]. |
| `no_module` | Disable loading external [modules]. | | `no_module` | Disable loading external [modules]. |
| `no_capture` | Disable [capturing][capture] external variables in [anonymous functions] and [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls. | | `no_capture` | Disable [capturing][capture] external variables in [anonymous functions] and [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls. |
| `no_std` | Build for `no-std`. Notice that additional dependencies will be pulled in to replace `std` features. | | `no_shared` | Disable sharing of data values. |
| `no_std` | Build for `no-std` (implies `no_shared`). Notice that additional dependencies will be pulled in to replace `std` features. |
| `serde` | Enable serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies. | | `serde` | Enable serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies. |
| `internals` | Expose internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version. | | `internals` | Expose internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version. |
| `unicode-xid-ident` | Allow [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers. | | `unicode-xid-ident` | Allow [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers. |