Make tables casing consistent.
This commit is contained in:
parent
9fcbda1ba4
commit
12e9a8567d
@ -5,34 +5,34 @@ Keywords List
|
|||||||
|
|
||||||
| Keyword | Description | Inactive under | Overloadable |
|
| Keyword | Description | Inactive under | Overloadable |
|
||||||
| :-------------------: | ---------------------------------------- | :-------------: | :----------: |
|
| :-------------------: | ---------------------------------------- | :-------------: | :----------: |
|
||||||
| `true` | Boolean true literal | | No |
|
| `true` | boolean true literal | | no |
|
||||||
| `false` | Boolean false literal | | No |
|
| `false` | boolean false literal | | no |
|
||||||
| `let` | Variable declaration | | No |
|
| `let` | variable declaration | | no |
|
||||||
| `const` | Constant declaration | | No |
|
| `const` | constant declaration | | no |
|
||||||
| `is_shared` | Is a value shared? | | No |
|
| `is_shared` | is a value shared? | | no |
|
||||||
| `if` | If statement | | No |
|
| `if` | if statement | | no |
|
||||||
| `else` | else block of if statement | | No |
|
| `else` | else block of if statement | | no |
|
||||||
| `while` | While loop | | No |
|
| `while` | while loop | | no |
|
||||||
| `loop` | Infinite loop | | No |
|
| `loop` | infinite loop | | no |
|
||||||
| `for` | For loop | | No |
|
| `for` | for loop | | no |
|
||||||
| `in` | Containment test, part of for loop | | No |
|
| `in` | containment test, part of for loop | | no |
|
||||||
| `continue` | Continue a loop at the next iteration | | No |
|
| `continue` | continue a loop at the next iteration | | no |
|
||||||
| `break` | Loop breaking | | No |
|
| `break` | loop breaking | | no |
|
||||||
| `return` | Return value | | No |
|
| `return` | return value | | no |
|
||||||
| `throw` | Throw exception | | No |
|
| `throw` | throw exception | | no |
|
||||||
| `import` | Import module | [`no_module`] | No |
|
| `import` | import module | [`no_module`] | no |
|
||||||
| `export` | Export variable | [`no_module`] | No |
|
| `export` | export variable | [`no_module`] | no |
|
||||||
| `as` | Alias for variable export | [`no_module`] | No |
|
| `as` | alias for variable export | [`no_module`] | no |
|
||||||
| `private` | Mark function private | [`no_function`] | No |
|
| `private` | mark function private | [`no_function`] | no |
|
||||||
| `fn` (lower-case `f`) | Function definition | [`no_function`] | No |
|
| `fn` (lower-case `f`) | function definition | [`no_function`] | no |
|
||||||
| `Fn` (capital `F`) | Function to create a [function pointer] | | Yes |
|
| `Fn` (capital `F`) | function to create a [function pointer] | | yes |
|
||||||
| `call` | Call a [function pointer] | | No |
|
| `call` | call a [function pointer] | | no |
|
||||||
| `curry` | Curry a [function pointer] | | No |
|
| `curry` | curry a [function pointer] | | no |
|
||||||
| `this` | Reference to base object for method call | [`no_function`] | No |
|
| `this` | reference to base object for method call | [`no_function`] | no |
|
||||||
| `type_of` | Get type name of value | | Yes |
|
| `type_of` | get type name of value | | yes |
|
||||||
| `print` | Print value | | Yes |
|
| `print` | print value | | yes |
|
||||||
| `debug` | Print value in debug format | | Yes |
|
| `debug` | print value in debug format | | yes |
|
||||||
| `eval` | Evaluate script | | Yes |
|
| `eval` | evaluate script | | yes |
|
||||||
|
|
||||||
|
|
||||||
Reserved Keywords
|
Reserved Keywords
|
||||||
@ -40,32 +40,32 @@ Reserved Keywords
|
|||||||
|
|
||||||
| Keyword | Potential usage |
|
| Keyword | Potential usage |
|
||||||
| --------- | --------------------- |
|
| --------- | --------------------- |
|
||||||
| `var` | Variable declaration |
|
| `var` | variable declaration |
|
||||||
| `static` | Variable declaration |
|
| `static` | variable declaration |
|
||||||
| `shared` | Share value |
|
| `shared` | share value |
|
||||||
| `do` | Looping |
|
| `do` | looping |
|
||||||
| `each` | Looping |
|
| `each` | looping |
|
||||||
| `then` | Control flow |
|
| `then` | control flow |
|
||||||
| `goto` | Control flow |
|
| `goto` | control flow |
|
||||||
| `exit` | Control flow |
|
| `exit` | control flow |
|
||||||
| `switch` | Matching |
|
| `switch` | matching |
|
||||||
| `match` | Matching |
|
| `match` | matching |
|
||||||
| `case` | Matching |
|
| `case` | matching |
|
||||||
| `public` | Function/field access |
|
| `public` | function/field access |
|
||||||
| `new` | Constructor |
|
| `new` | constructor |
|
||||||
| `try` | Trap exception |
|
| `try` | trap exception |
|
||||||
| `catch` | Catch exception |
|
| `catch` | catch exception |
|
||||||
| `use` | Import namespace |
|
| `use` | import namespace |
|
||||||
| `with` | Scope |
|
| `with` | scope |
|
||||||
| `module` | Module |
|
| `module` | module |
|
||||||
| `package` | Package |
|
| `package` | package |
|
||||||
| `spawn` | Threading |
|
| `spawn` | threading |
|
||||||
| `go` | Threading |
|
| `go` | threading |
|
||||||
| `await` | Async |
|
| `await` | async |
|
||||||
| `async` | Async |
|
| `async` | async |
|
||||||
| `sync` | Async |
|
| `sync` | async |
|
||||||
| `yield` | Async |
|
| `yield` | async |
|
||||||
| `default` | Special value |
|
| `default` | special value |
|
||||||
| `void` | Special value |
|
| `void` | special value |
|
||||||
| `null` | Special value |
|
| `null` | special value |
|
||||||
| `nil` | Special value |
|
| `nil` | special value |
|
||||||
|
@ -9,29 +9,28 @@ Operators
|
|||||||
|
|
||||||
| Operator | Description | Binary? | Binding direction |
|
| Operator | Description | Binary? | Binding direction |
|
||||||
| :---------------: | ------------------------------ | :-----: | :---------------: |
|
| :---------------: | ------------------------------ | :-----: | :---------------: |
|
||||||
| `+` | Add | Yes | Left |
|
| `+` | add | yes | left |
|
||||||
| `-` | Subtract, Minus | Yes/No | Left |
|
| `-` | subtract, Minus | yes/no | left |
|
||||||
| `*` | Multiply | Yes | Left |
|
| `*` | multiply | yes | left |
|
||||||
| `/` | Divide | Yes | Left |
|
| `/` | divide | yes | left |
|
||||||
| `%` | Modulo | Yes | Left |
|
| `%` | modulo | yes | left |
|
||||||
| `~` | Power | Yes | Left |
|
| `~` | power | yes | left |
|
||||||
| `>>` | Right bit-shift | Yes | Left |
|
| `>>` | right bit-shift | yes | left |
|
||||||
| `<<` | Left bit-shift | Yes | Left |
|
| `<<` | left bit-shift | yes | left |
|
||||||
| `&` | Bit-wise _And_, Boolean _And_ | Yes | Left |
|
| `&` | bit-wise _And_, boolean _And_ | yes | left |
|
||||||
| <code>\|</code> | Bit-wise _Or_, Boolean _Or_ | Yes | Left |
|
| <code>\|</code> | bit-wise _Or_, boolean _Or_ | yes | left |
|
||||||
| `^` | Bit-wise _Xor_, Boolean _Xor_ | Yes | Left |
|
| `^` | bit-wise _Xor_, boolean _Xor_ | yes | left |
|
||||||
| `==` | Equals to | Yes | Left |
|
| `==` | equals to | yes | left |
|
||||||
| `~=` | Not equals to | Yes | Left |
|
| `~=` | not equals to | yes | left |
|
||||||
| `>` | Greater than | Yes | Left |
|
| `>` | greater than | yes | left |
|
||||||
| `>=` | Greater than or equals to | Yes | Left |
|
| `>=` | greater than or equals to | yes | left |
|
||||||
| `<` | Less than | Yes | Left |
|
| `<` | less than | yes | left |
|
||||||
| `<=` | Less than or equals to | Yes | Left |
|
| `<=` | less than or equals to | yes | left |
|
||||||
| `>=` | Greater than or equals to | Yes | Left |
|
| `&&` | boolean _And_ (short-circuits) | yes | left |
|
||||||
| `&&` | Boolean _And_ (short-circuits) | Yes | Left |
|
| <code>\|\|</code> | boolean _Or_ (short-circuits) | yes | left |
|
||||||
| <code>\|\|</code> | Boolean _Or_ (short-circuits) | Yes | Left |
|
| `!` | boolean _Not_ | no | left |
|
||||||
| `!` | Boolean _Not_ | No | Left |
|
| `[` .. `]` | indexing | yes | right |
|
||||||
| `[` .. `]` | Indexing | Yes | Right |
|
| `.` | property access, method call | yes | right |
|
||||||
| `.` | Property access, Method call | Yes | Right |
|
|
||||||
|
|
||||||
|
|
||||||
Symbols
|
Symbols
|
||||||
@ -39,8 +38,8 @@ Symbols
|
|||||||
|
|
||||||
| Symbol | Description |
|
| Symbol | Description |
|
||||||
| ------------ | ------------------------ |
|
| ------------ | ------------------------ |
|
||||||
| `:` | Property value separator |
|
| `:` | property value separator |
|
||||||
| `::` | Module path separator |
|
| `::` | module path separator |
|
||||||
| `#` | _Reserved_ |
|
| `#` | _Reserved_ |
|
||||||
| `=>` | _Reserved_ |
|
| `=>` | _Reserved_ |
|
||||||
| `->` | _Reserved_ |
|
| `->` | _Reserved_ |
|
||||||
|
@ -5,14 +5,14 @@ Engine Configuration Options
|
|||||||
|
|
||||||
A number of other configuration options are available from the `Engine` to fine-tune behavior and safeguards.
|
A number of other configuration options are available from the `Engine` to fine-tune behavior and safeguards.
|
||||||
|
|
||||||
| Method | Not available under | Description |
|
| Method | Not available under | Description |
|
||||||
| ------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
| ------------------------ | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `set_optimization_level` | [`no_optimize`] | Set the amount of script _optimizations_ performed. See [script optimization]. |
|
| `set_optimization_level` | [`no_optimize`] | sets the amount of script _optimizations_ performed. See [script optimization]. |
|
||||||
| `set_max_expr_depths` | [`unchecked`] | Set the maximum nesting levels of an expression/statement. See [maximum statement depth]. |
|
| `set_max_expr_depths` | [`unchecked`] | sets the maximum nesting levels of an expression/statement. See [maximum statement depth]. |
|
||||||
| `set_max_call_levels` | [`unchecked`] | Set the maximum number of function call levels (default 50) to avoid infinite recursion. See [maximum call stack depth]. |
|
| `set_max_call_levels` | [`unchecked`] | sets the maximum number of function call levels (default 50) to avoid infinite recursion. See [maximum call stack depth]. |
|
||||||
| `set_max_operations` | [`unchecked`] | Set the maximum number of _operations_ that a script is allowed to consume. See [maximum number of operations]. |
|
| `set_max_operations` | [`unchecked`] | sets the maximum number of _operations_ that a script is allowed to consume. See [maximum number of operations]. |
|
||||||
| `set_max_modules` | [`unchecked`] | Set the maximum number of [modules] that a script is allowed to load. See [maximum number of modules]. |
|
| `set_max_modules` | [`unchecked`] | sets the maximum number of [modules] that a script is allowed to load. See [maximum number of modules]. |
|
||||||
| `set_max_string_size` | [`unchecked`] | Set the maximum length (in UTF-8 bytes) for [strings]. See [maximum length of strings]. |
|
| `set_max_string_size` | [`unchecked`] | sets the maximum length (in UTF-8 bytes) for [strings]. See [maximum length of strings]. |
|
||||||
| `set_max_array_size` | [`unchecked`], [`no_index`] | Set the maximum size for [arrays]. See [maximum size of arrays]. |
|
| `set_max_array_size` | [`unchecked`], [`no_index`] | sets the maximum size for [arrays]. See [maximum size of arrays]. |
|
||||||
| `set_max_map_size` | [`unchecked`], [`no_object`] | Set the maximum number of properties for [object maps]. See [maximum size of object maps]. |
|
| `set_max_map_size` | [`unchecked`], [`no_object`] | sets the maximum number of properties for [object maps]. See [maximum size of object maps]. |
|
||||||
| `disable_symbol` | | Disable a certain keyword or operator. See [disable keywords and operators]. |
|
| `disable_symbol` | | disables a certain keyword or operator. See [disable keywords and operators]. |
|
||||||
|
@ -37,7 +37,7 @@ The following methods (mostly defined in the [`BasicArrayPackage`][packages] but
|
|||||||
| `append` | array to append | concatenates the second array to the end of the first |
|
| `append` | array to append | concatenates the second array to the end of the first |
|
||||||
| `+=` operator | array, array to append | concatenates the second array to the end of the first |
|
| `+=` operator | array, array to append | concatenates the second array to the end of the first |
|
||||||
| `+` operator | first array, second array | concatenates the first array with the second |
|
| `+` operator | first array, second array | concatenates the first array with the second |
|
||||||
| `insert` | element to insert, position<br/>(beginning if <= 0, end if >= length) | insert an element at a certain index |
|
| `insert` | element to insert, position<br/>(beginning if <= 0, end if >= length) | inserts an element at a certain index |
|
||||||
| `pop` | _none_ | removes the last element and returns it ([`()`] if empty) |
|
| `pop` | _none_ | removes the last element and returns it ([`()`] if empty) |
|
||||||
| `shift` | _none_ | removes the first element and returns it ([`()`] if empty) |
|
| `shift` | _none_ | removes the first element and returns it ([`()`] if empty) |
|
||||||
| `remove` | index | removes an element at a particular index and returns it, or returns [`()`] if the index is not valid |
|
| `remove` | index | removes an element at a particular index and returns it, or returns [`()`] if the index is not valid |
|
||||||
@ -52,7 +52,7 @@ Use Custom Types With Arrays
|
|||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
To use a [custom type] with arrays, a number of array functions need to be manually implemented,
|
To use a [custom type] with arrays, a number of array functions need to be manually implemented,
|
||||||
in particular `push`, `pad` and the `+=` operator. In addition, the `==` operator must be
|
in particular `push`, `insert`, `pad` and the `+=` operator. In addition, the `==` operator must be
|
||||||
implemented for the [custom type] in order to support the `in` operator which uses `==` to
|
implemented for the [custom type] in order to support the `in` operator which uses `==` to
|
||||||
compare elements.
|
compare elements.
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ In general, there are two types of _namespaces_ where functions are looked up:
|
|||||||
|
|
||||||
| Namespace | Source | Lookup method | How Many |
|
| Namespace | Source | Lookup method | How Many |
|
||||||
| --------- | ---------------------------------------------------------------------- | --------------------------------- | :----------------------: |
|
| --------- | ---------------------------------------------------------------------- | --------------------------------- | :----------------------: |
|
||||||
| Global | `Engine::register_XXX` API, [`AST`] being evaluated, [packages] loaded | Simple function name | One |
|
| Global | `Engine::register_XXX` API, [`AST`] being evaluated, [packages] loaded | simple function name | one |
|
||||||
| Module | [`Module`] | Namespace-qualified function name | As many as [`import`]-ed |
|
| Module | [`Module`] | namespace-qualified function name | as many as [`import`]-ed |
|
||||||
|
|
||||||
|
|
||||||
Global Namespace
|
Global Namespace
|
||||||
|
@ -7,19 +7,19 @@ 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 | |
|
||||||
| `is_shared` | | Shared values | [`no_closure`] |
|
| `is_shared` | | shared values | [`no_closure`] |
|
||||||
| `if`, `else` | `then`, `goto`, `exit` | Control flow | |
|
| `if`, `else` | `then`, `goto`, `exit` | control flow | |
|
||||||
| | `switch`, `match`, `case` | Matching | |
|
| | `switch`, `match`, `case` | matching | |
|
||||||
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | Looping | |
|
| `while`, `loop`, `for`, `in`, `continue`, `break` | `do`, `each` | looping | |
|
||||||
| `fn`, `private` | `public`, `new` | Functions | [`no_function`] |
|
| `fn`, `private` | `public`, `new` | functions | [`no_function`] |
|
||||||
| `return` | | Return values | |
|
| `return` | | return values | |
|
||||||
| `throw` | `try`, `catch` | Throw exceptions | |
|
| `throw` | `try`, `catch` | throw exceptions | |
|
||||||
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | Modules/packages | [`no_module`] |
|
| `import`, `export`, `as` | `use`, `with`, `module`, `package` | modules/packages | [`no_module`] |
|
||||||
| `Fn`, `call`, `curry` | | Function pointers | |
|
| `Fn`, `call`, `curry` | | function pointers | |
|
||||||
| | `spawn`, `go`, `sync`, `async`, `await`, `yield` | Threading/async | |
|
| | `spawn`, `go`, `sync`, `async`, `await`, `yield` | threading/async | |
|
||||||
| `type_of`, `print`, `debug`, `eval` | | Special functions | |
|
| `type_of`, `print`, `debug`, `eval` | | special functions | |
|
||||||
| | `default`, `void`, `null`, `nil` | Special values | |
|
| | `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.
|
||||||
|
@ -45,11 +45,11 @@ Boolean operators
|
|||||||
|
|
||||||
| Operator | Description |
|
| Operator | Description |
|
||||||
| ----------------- | ------------------------------------- |
|
| ----------------- | ------------------------------------- |
|
||||||
| `!` | Boolean _Not_ |
|
| `!` | boolean _Not_ |
|
||||||
| `&&` | Boolean _And_ (short-circuits) |
|
| `&&` | boolean _And_ (short-circuits) |
|
||||||
| <code>\|\|</code> | Boolean _Or_ (short-circuits) |
|
| <code>\|\|</code> | boolean _Or_ (short-circuits) |
|
||||||
| `&` | Boolean _And_ (doesn't short-circuit) |
|
| `&` | boolean _And_ (doesn't short-circuit) |
|
||||||
| <code>\|</code> | Boolean _Or_ (doesn't short-circuit) |
|
| <code>\|</code> | boolean _Or_ (doesn't short-circuit) |
|
||||||
|
|
||||||
Double boolean operators `&&` and `||` _short-circuit_, meaning that the second operand will not be evaluated
|
Double boolean operators `&&` and `||` _short-circuit_, meaning that the second operand will not be evaluated
|
||||||
if the first one already proves the condition wrong.
|
if the first one already proves the condition wrong.
|
||||||
|
@ -49,7 +49,7 @@ The following table illustrates the differences:
|
|||||||
|
|
||||||
| Function type | Parameters | Object reference | Function signature |
|
| Function type | Parameters | Object reference | Function signature |
|
||||||
| :-----------: | :--------: | :--------------------: | :-----------------------------------------------------: |
|
| :-----------: | :--------: | :--------------------: | :-----------------------------------------------------: |
|
||||||
| Native Rust | _n_ + 1 | First `&mut` parameter | `fn method<T, U, V>`<br/>`(obj: &mut T, x: U, y: V) {}` |
|
| Native Rust | _n_ + 1 | first `&mut` parameter | `fn method<T, U, V>`<br/>`(obj: &mut T, x: U, y: V) {}` |
|
||||||
| Rhai script | _n_ | `this` | `fn method(x, y) {}` |
|
| Rhai script | _n_ | `this` | `fn method(x, y) {}` |
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ Integer Functions
|
|||||||
The following standard functions (defined in the [`BasicMathPackage`][packages] but excluded if using a [raw `Engine`])
|
The following standard functions (defined in the [`BasicMathPackage`][packages] but excluded if using a [raw `Engine`])
|
||||||
operate on `i8`, `i16`, `i32`, `i64`, `f32` and `f64` only:
|
operate on `i8`, `i16`, `i32`, `i64`, `f32` and `f64` only:
|
||||||
|
|
||||||
| Function | No available under | Description |
|
| Function | No available under | Description |
|
||||||
| -------- | :----------------: | ---------------------------------------------------------------------- |
|
| -------- | :----------------: | ----------------------------------------------------------------------- |
|
||||||
| `abs` | | absolute value |
|
| `abs` | | absolute value |
|
||||||
| `sign` | | return -1 (`INT`) if the number is negative, +1 if positive, 0 if zero |
|
| `sign` | | returns -1 (`INT`) if the number is negative, +1 if positive, 0 if zero |
|
||||||
|
|
||||||
|
|
||||||
Floating-Point Functions
|
Floating-Point Functions
|
||||||
@ -39,8 +39,8 @@ Conversion Functions
|
|||||||
The following standard functions (defined in the [`BasicMathPackage`][packages] but excluded if using a [raw `Engine`])
|
The following standard functions (defined in the [`BasicMathPackage`][packages] but excluded if using a [raw `Engine`])
|
||||||
parse numbers:
|
parse numbers:
|
||||||
|
|
||||||
| Function | No available under | Description |
|
| Function | No available under | Description |
|
||||||
| --------------- | :----------------: | -------------------------------------------------- |
|
| --------------- | :----------------: | --------------------------------------------------- |
|
||||||
| [`to_float`] | [`no_float`] | convert an integer type to `FLOAT` |
|
| [`to_float`] | [`no_float`] | converts an integer type to `FLOAT` |
|
||||||
| [`parse_int`] | | convert a [string] to `INT` with an optional radix |
|
| [`parse_int`] | | converts a [string] to `INT` with an optional radix |
|
||||||
| [`parse_float`] | [`no_float`] | convert a [string] to `FLOAT` |
|
| [`parse_float`] | [`no_float`] | converts a [string] to `FLOAT` |
|
||||||
|
@ -10,8 +10,8 @@ Unary Operators
|
|||||||
|
|
||||||
| Operator | Description |
|
| Operator | Description |
|
||||||
| -------- | ----------- |
|
| -------- | ----------- |
|
||||||
| `+` | Positive |
|
| `+` | positive |
|
||||||
| `-` | Negative |
|
| `-` | negative |
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let number = -5;
|
let number = -5;
|
||||||
@ -24,17 +24,17 @@ Binary Operators
|
|||||||
|
|
||||||
| Operator | Description | Integers only |
|
| Operator | Description | Integers only |
|
||||||
| --------------- | ---------------------------------------------------- | :-----------: |
|
| --------------- | ---------------------------------------------------- | :-----------: |
|
||||||
| `+` | Plus | |
|
| `+` | plus | |
|
||||||
| `-` | Minus | |
|
| `-` | minus | |
|
||||||
| `*` | Multiply | |
|
| `*` | multiply | |
|
||||||
| `/` | Divide (integer division if acting on integer types) | |
|
| `/` | divide (integer division if acting on integer types) | |
|
||||||
| `%` | Modulo (remainder) | |
|
| `%` | modulo (remainder) | |
|
||||||
| `~` | Power | |
|
| `~` | power | |
|
||||||
| `&` | Bit-wise _And_ | Yes |
|
| `&` | bit-wise _And_ | Yes |
|
||||||
| <code>\|</code> | Bit-wise _Or_ | Yes |
|
| <code>\|</code> | bit-wise _Or_ | Yes |
|
||||||
| `^` | Bit-wise _Xor_ | Yes |
|
| `^` | bit-wise _Xor_ | Yes |
|
||||||
| `<<` | Left bit-shift | Yes |
|
| `<<` | left bit-shift | Yes |
|
||||||
| `>>` | Right bit-shift | Yes |
|
| `>>` | right bit-shift | Yes |
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
let x = (1 + 2) * (6 - 4) / 2; // arithmetic, with parentheses
|
let x = (1 + 2) * (6 - 4) / 2; // arithmetic, with parentheses
|
||||||
|
@ -11,11 +11,11 @@ individual functions instead of a full-blown [plugin module].
|
|||||||
Macros
|
Macros
|
||||||
------
|
------
|
||||||
|
|
||||||
| Macro | Apply to | Behavior |
|
| Macro | Apply to | Description |
|
||||||
| ----------------------- | --------------------------------------------------------------- | -------------------------------------------------------- |
|
| ----------------------- | --------------------------------------------------------------- | ------------------------------------------------------------- |
|
||||||
| `#[export_fn]` | Rust function defined in a Rust module | Export the function |
|
| `#[export_fn]` | rust function defined in a Rust module | exports the function |
|
||||||
| `register_exported_fn!` | [`Engine`] instance, register name string, use path to function | Register function into an [`Engine`] under specific name |
|
| `register_exported_fn!` | [`Engine`] instance, register name string, use path to function | registers the function into an [`Engine`] under specific name |
|
||||||
| `set_exported_fn!` | [`Module`] instance, register name string, use path to function | Register function into an [`Module`] under specific name |
|
| `set_exported_fn!` | [`Module`] instance, register name string, use path to function | registers the function into an [`Module`] under specific name |
|
||||||
|
|
||||||
|
|
||||||
`#[export_fn]` and `register_exported_fn!`
|
`#[export_fn]` and `register_exported_fn!`
|
||||||
|
@ -204,11 +204,11 @@ The above function can be called in five ways:
|
|||||||
|
|
||||||
| Parameter for `#[rhai_fn(...)]` | Type | Call style |
|
| Parameter for `#[rhai_fn(...)]` | Type | Call style |
|
||||||
| ------------------------------- | :-------------: | --------------------------------------------- |
|
| ------------------------------- | :-------------: | --------------------------------------------- |
|
||||||
| `name = "get_prop_value"` | Method function | `get_prop_value(x, 0)`, `x.get_prop_value(0)` |
|
| `name = "get_prop_value"` | method function | `get_prop_value(x, 0)`, `x.get_prop_value(0)` |
|
||||||
| `name = "prop"` | Method function | `prop(x, 0)`, `x.prop(0)` |
|
| `name = "prop"` | method function | `prop(x, 0)`, `x.prop(0)` |
|
||||||
| `name = "+"` | Operator | `x + 42` |
|
| `name = "+"` | operator | `x + 42` |
|
||||||
| `set = "prop"` | Setter | `x.prop = 42` |
|
| `set = "prop"` | setter | `x.prop = 42` |
|
||||||
| `index_get` | Index getter | `x[0]` |
|
| `index_get` | index getter | `x[0]` |
|
||||||
|
|
||||||
|
|
||||||
Fallible Functions
|
Fallible Functions
|
||||||
@ -244,11 +244,11 @@ mod my_module {
|
|||||||
|
|
||||||
Parameters can be applied to the `#[export_module]` attribute to override its default behavior.
|
Parameters can be applied to the `#[export_module]` attribute to override its default behavior.
|
||||||
|
|
||||||
| Parameter | Behavior |
|
| Parameter | Description |
|
||||||
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| _None_ | Export only public (i.e. `pub`) functions |
|
| _none_ | exports only public (i.e. `pub`) functions |
|
||||||
| `export_all` | Export all functions (including private, non-`pub` functions); use `#[rhai_fn(skip)]` on individual functions to avoid export |
|
| `export_all` | exports all functions (including private, non-`pub` functions); use `#[rhai_fn(skip)]` on individual functions to avoid export |
|
||||||
| `export_prefix = "..."` | Export functions (including private, non-`pub` functions) with names starting with a specific prefix |
|
| `export_prefix = "..."` | exports functions (including private, non-`pub` functions) with names starting with a specific prefix |
|
||||||
|
|
||||||
|
|
||||||
Inner Attributes
|
Inner Attributes
|
||||||
@ -260,12 +260,12 @@ Inner attributes can be applied to the inner items of a module to tweak the expo
|
|||||||
|
|
||||||
Parameters should be set on inner attributes to specify the desired behavior.
|
Parameters should be set on inner attributes to specify the desired behavior.
|
||||||
|
|
||||||
| Attribute Parameter | Use with | Apply to | Behavior |
|
| Attribute Parameter | Use with | Apply to | Description |
|
||||||
| ------------------- | --------------------------- | -------------------------------------------------------- | ----------------------------------------------------- |
|
| ------------------- | --------------------------- | -------------------------------------------------------- | ------------------------------------------------------ |
|
||||||
| `skip` | `#[rhai_fn]`, `#[rhai_mod]` | Function or sub-module | Do not export this function/sub-module |
|
| `skip` | `#[rhai_fn]`, `#[rhai_mod]` | function or sub-module | do not export this function/sub-module |
|
||||||
| `name = "..."` | `#[rhai_fn]`, `#[rhai_mod]` | Function or sub-module | Register function/sub-module under the specified name |
|
| `name = "..."` | `#[rhai_fn]`, `#[rhai_mod]` | function or sub-module | registers function/sub-module under the specified name |
|
||||||
| `get = "..."` | `#[rhai_fn]` | Function with `&mut` first parameter | Register a getter for the named property |
|
| `get = "..."` | `#[rhai_fn]` | function with `&mut` first parameter | registers a getter for the named property |
|
||||||
| `set = "..."` | `#[rhai_fn]` | Function with `&mut` first parameter | Register a setter for the named property |
|
| `set = "..."` | `#[rhai_fn]` | function with `&mut` first parameter | registers a setter for the named property |
|
||||||
| `index_get` | `#[rhai_fn]` | Function with `&mut` first parameter | Register an index getter |
|
| `index_get` | `#[rhai_fn]` | function with `&mut` first parameter | registers an index getter |
|
||||||
| `index_set` | `#[rhai_fn]` | Function with `&mut` first parameter | Register an index setter |
|
| `index_set` | `#[rhai_fn]` | function with `&mut` first parameter | registers an index setter |
|
||||||
| `return_raw` | `#[rhai_fn]` | Function returning `Result<Dynamic, Box<EvalAltResult>>` | Mark this as a [fallible function] |
|
| `return_raw` | `#[rhai_fn]` | function returning `Result<Dynamic, Box<EvalAltResult>>` | marks this as a [fallible function] |
|
||||||
|
@ -161,8 +161,8 @@ x.type_of() == "Hello";
|
|||||||
Use the Custom Type With Arrays
|
Use the Custom Type With Arrays
|
||||||
------------------------------
|
------------------------------
|
||||||
|
|
||||||
The `push` and `pad` functions, as well as the `+=` operator, for [arrays] are only defined for
|
The `push`, `insert`, `pad` functions, as well as the `+=` operator, for [arrays] are only
|
||||||
standard built-in types. For custom types, type-specific versions must be registered:
|
defined for standard built-in types. For custom types, type-specific versions must be registered:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
engine
|
engine
|
||||||
@ -170,6 +170,14 @@ engine
|
|||||||
list.push(Dynamic::from(item));
|
list.push(Dynamic::from(item));
|
||||||
}).register_fn("+=", |list: &mut Array, item: TestStruct| {
|
}).register_fn("+=", |list: &mut Array, item: TestStruct| {
|
||||||
list.push(Dynamic::from(item));
|
list.push(Dynamic::from(item));
|
||||||
|
}).register_fn("insert", |list: &mut Array, position: i64, item: TestStruct| {
|
||||||
|
if position <= 0 {
|
||||||
|
list.insert(0, Dynamic::from(item));
|
||||||
|
} else if (position as usize) >= list.len() - 1 {
|
||||||
|
list.push(item);
|
||||||
|
} else {
|
||||||
|
list.insert(position as usize, Dynamic::from(item));
|
||||||
|
}
|
||||||
}).register_fn("pad", |list: &mut Array, len: i64, item: TestStruct| {
|
}).register_fn("pad", |list: &mut Array, len: i64, item: TestStruct| {
|
||||||
if len as usize > list.len() {
|
if len as usize > list.len() {
|
||||||
list.resize(len as usize, item);
|
list.resize(len as usize, item);
|
||||||
|
@ -11,11 +11,11 @@ Getters and setters are disabled when the [`no_object`] feature is used.
|
|||||||
|
|
||||||
| `Engine` API | Description | Return Value of Function |
|
| `Engine` API | Description | Return Value of Function |
|
||||||
| --------------------- | ------------------------------------------------- | :-----------------------------------: |
|
| --------------------- | ------------------------------------------------- | :-----------------------------------: |
|
||||||
| `register_get` | Register a getter | _Any_ |
|
| `register_get` | register a getter | _any_ |
|
||||||
| `register_set` | Register a setter | _None_ |
|
| `register_set` | register a setter | _none_ |
|
||||||
| `register_get_set` | Short-hand to register both a getter and a setter | _None_ |
|
| `register_get_set` | short-hand to register both a getter and a setter | _none_ |
|
||||||
| `register_get_result` | Register a getter | `Result<Dynamic, Box<EvalAltResult>>` |
|
| `register_get_result` | register a getter | `Result<Dynamic, Box<EvalAltResult>>` |
|
||||||
| `register_set_result` | Register a setter | `Result<(), Box<EvalAltResult>>` |
|
| `register_set_result` | register a setter | `Result<(), Box<EvalAltResult>>` |
|
||||||
|
|
||||||
|
|
||||||
Cannot Override Object Maps
|
Cannot Override Object Maps
|
||||||
|
@ -15,11 +15,11 @@ Indexers are disabled when the [`no_index`] feature is used.
|
|||||||
|
|
||||||
| `Engine` API | Description | Return Value of Function |
|
| `Engine` API | Description | Return Value of Function |
|
||||||
| ----------------------------- | -------------------------------------------------------- | :-----------------------------------: |
|
| ----------------------------- | -------------------------------------------------------- | :-----------------------------------: |
|
||||||
| `register_indexer_get` | Register an index getter | _Any_ |
|
| `register_indexer_get` | register an index getter | _any_ |
|
||||||
| `register_indexer_set` | Register an index setter | _None_ |
|
| `register_indexer_set` | register an index setter | _none_ |
|
||||||
| `register_indexer_get_set` | Short-hand to register both an index getter and a setter | _None_ |
|
| `register_indexer_get_set` | short-hand to register both an index getter and a setter | _none_ |
|
||||||
| `register_indexer_get_result` | Register an index getter | `Result<Dynamic, Box<EvalAltResult>>` |
|
| `register_indexer_get_result` | register an index getter | `Result<Dynamic, Box<EvalAltResult>>` |
|
||||||
| `register_indexer_set_result` | Register an index setter | `Result<(), Box<EvalAltResult>>` |
|
| `register_indexer_set_result` | register an index setter | `Result<(), Box<EvalAltResult>>` |
|
||||||
|
|
||||||
|
|
||||||
Cannot Override Arrays, Object Maps and Strings
|
Cannot Override Arrays, Object Maps and Strings
|
||||||
|
@ -9,19 +9,19 @@ Built-In Packages
|
|||||||
|
|
||||||
| Package | Description | In `Core` | In `Standard` |
|
| Package | Description | In `Core` | In `Standard` |
|
||||||
| ---------------------- | ------------------------------------------------------------------------------------------------------ | :-------: | :-----------: |
|
| ---------------------- | ------------------------------------------------------------------------------------------------------ | :-------: | :-----------: |
|
||||||
| `ArithmeticPackage` | Arithmetic operators (e.g. `+`, `-`, `*`, `/`) for numeric types that are not built in (e.g. `u16`) | Yes | Yes |
|
| `ArithmeticPackage` | arithmetic operators (e.g. `+`, `-`, `*`, `/`) for numeric types that are not built in (e.g. `u16`) | yes | yes |
|
||||||
| `BasicIteratorPackage` | Numeric ranges (e.g. `range(1, 10)`) | Yes | Yes |
|
| `BasicIteratorPackage` | numeric ranges (e.g. `range(1, 10)`) | yes | yes |
|
||||||
| `LogicPackage` | Logical and comparison operators (e.g. `==`, `>`) for numeric types that are not built in (e.g. `u16`) | Yes | Yes |
|
| `LogicPackage` | logical and comparison operators (e.g. `==`, `>`) for numeric types that are not built in (e.g. `u16`) | yes | yes |
|
||||||
| `BasicStringPackage` | Basic string functions (e.g. `print`, `debug`, `len`) that are not built in | Yes | Yes |
|
| `BasicStringPackage` | basic string functions (e.g. `print`, `debug`, `len`) that are not built in | yes | yes |
|
||||||
| `BasicTimePackage` | Basic time functions (e.g. [timestamps]) | Yes | Yes |
|
| `BasicTimePackage` | basic time functions (e.g. [timestamps]) | yes | yes |
|
||||||
| `MoreStringPackage` | Additional string functions, including converting common types to string | No | Yes |
|
| `MoreStringPackage` | additional string functions, including converting common types to string | no | yes |
|
||||||
| `BasicMathPackage` | Basic math functions (e.g. `sin`, `sqrt`) | No | Yes |
|
| `BasicMathPackage` | basic math functions (e.g. `sin`, `sqrt`) | no | yes |
|
||||||
| `BasicArrayPackage` | Basic [array] functions (not available under `no_index`) | No | Yes |
|
| `BasicArrayPackage` | basic [array] functions (not available under `no_index`) | no | yes |
|
||||||
| `BasicMapPackage` | Basic [object map] functions (not available under `no_object`) | No | Yes |
|
| `BasicMapPackage` | basic [object map] functions (not available under `no_object`) | no | yes |
|
||||||
| `BasicFnPackage` | Basic methods for [function pointers]. | Yes | Yes |
|
| `BasicFnPackage` | basic methods for [function pointers]. | yes | yes |
|
||||||
| `EvalPackage` | Disable [`eval`] | No | No |
|
| `EvalPackage` | disable [`eval`] | no | no |
|
||||||
| `CorePackage` | Basic essentials | Yes | Yes |
|
| `CorePackage` | basic essentials | yes | yes |
|
||||||
| `StandardPackage` | Standard library (default for `Engine::new`) | No | Yes |
|
| `StandardPackage` | standard library (default for `Engine::new`) | no | yes |
|
||||||
|
|
||||||
|
|
||||||
Load the `CorePackage`
|
Load the `CorePackage`
|
||||||
|
@ -7,11 +7,11 @@ To use custom types for [`print`] and [`debug`], or convert its value into a [st
|
|||||||
it is necessary that the following functions be registered (assuming the custom type
|
it is necessary that the following functions be registered (assuming the custom type
|
||||||
is `T : Display + Debug`):
|
is `T : Display + Debug`):
|
||||||
|
|
||||||
| Function | Signature | Typical implementation | Usage |
|
| Function | Signature | Typical implementation | Usage |
|
||||||
| ----------- | ------------------------------------------------------------- | ------------------------------------- | --------------------------------------------------------------------------------------- |
|
| ----------- | ------------------------------------------------------------- | ------------------------------------- | ---------------------------------------------------------------------------------------- |
|
||||||
| `to_string` | <code>\|s: &mut T\| -> ImmutableString</code> | `s.to_string().into()` | Converts the custom type into a [string] |
|
| `to_string` | <code>\|s: &mut T\| -> ImmutableString</code> | `s.to_string().into()` | converts the custom type into a [string] |
|
||||||
| `print` | <code>\|s: &mut T\| -> ImmutableString</code> | `s.to_string().into()` | Converts the custom type into a [string] for the [`print`] statement |
|
| `print` | <code>\|s: &mut T\| -> ImmutableString</code> | `s.to_string().into()` | converts the custom type into a [string] for the [`print`] statement |
|
||||||
| `debug` | <code>\|s: &mut T\| -> ImmutableString</code> | `format!("{:?}", s).into()` | Converts the custom type into a [string] for the [`debug`] statement |
|
| `debug` | <code>\|s: &mut T\| -> ImmutableString</code> | `format!("{:?}", s).into()` | converts the custom type into a [string] for the [`debug`] statement |
|
||||||
| `+` | <code>\|s1: ImmutableString, s: T\| -> ImmutableString</code> | `s1 + s` | Append the custom type to another [string], for `print("Answer: " + type);` usage |
|
| `+` | <code>\|s1: ImmutableString, s: T\| -> ImmutableString</code> | `s1 + s` | appends the custom type to another [string], for `print("Answer: " + type);` usage |
|
||||||
| `+` | <code>\|s: T, s2: ImmutableString\| -> ImmutableString</code> | `s.to_string().push_str(&s2).into();` | Append another [string] to the custom type, for `print(type + " is the answer");` usage |
|
| `+` | <code>\|s: T, s2: ImmutableString\| -> ImmutableString</code> | `s.to_string().push_str(&s2).into();` | appends another [string] to the custom type, for `print(type + " is the answer");` usage |
|
||||||
| `+=` | <code>\|s1: &mut ImmutableString, s: T\|</code> | `s1 += s.to_string()` | Append the custom type to an existing [string], for `s += type;` usage |
|
| `+=` | <code>\|s1: &mut ImmutableString, s: T\|</code> | `s1 += s.to_string()` | appends the custom type to an existing [string], for `s += type;` usage |
|
||||||
|
@ -84,12 +84,12 @@ Extract Arguments
|
|||||||
|
|
||||||
To extract an argument from the `args` parameter (`&mut [&mut Dynamic]`), use the following:
|
To extract an argument from the `args` parameter (`&mut [&mut Dynamic]`), use the following:
|
||||||
|
|
||||||
| Argument type | Access (`n` = argument position) | Result |
|
| Argument type | Access (`n` = argument position) | Result |
|
||||||
| ------------------------------ | ------------------------------------- | ---------------------------------------------------------- |
|
| ------------------------------ | ------------------------------------- | --------------------------------------------------------- |
|
||||||
| [Primary type][standard types] | `args[n].clone().cast::<T>()` | Copy of value. |
|
| [Primary type][standard types] | `args[n].clone().cast::<T>()` | copy of value |
|
||||||
| Custom type | `args[n].read_lock::<T>().unwrap()` | Immutable reference to value. |
|
| Custom type | `args[n].read_lock::<T>().unwrap()` | immutable reference to value |
|
||||||
| Custom type (consumed) | `std::mem::take(args[n]).cast::<T>()` | The _consumed_ value.<br/>The original value becomes `()`. |
|
| Custom type (consumed) | `std::mem::take(args[n]).cast::<T>()` | the _consumed_ value.<br/>The original value becomes `()` |
|
||||||
| `this` object | `args[0].write_lock::<T>().unwrap()` | Mutable reference to value. |
|
| `this` object | `args[0].write_lock::<T>().unwrap()` | mutable reference to value |
|
||||||
|
|
||||||
When there is a mutable reference to the `this` object (i.e. the first argument),
|
When there is a mutable reference to the `this` object (i.e. the first argument),
|
||||||
there can be no other immutable references to `args`, otherwise the Rust borrow checker will complain.
|
there can be no other immutable references to `args`, otherwise the Rust borrow checker will complain.
|
||||||
|
@ -7,7 +7,7 @@ A number of traits, under the `rhai::` module namespace, provide additional func
|
|||||||
|
|
||||||
| Trait | Description | Methods |
|
| Trait | Description | Methods |
|
||||||
| ------------------ | ---------------------------------------------------------------------------------------- | --------------------------------------- |
|
| ------------------ | ---------------------------------------------------------------------------------------- | --------------------------------------- |
|
||||||
| `RegisterFn` | Trait for registering functions | `register_fn` |
|
| `RegisterFn` | trait for registering functions | `register_fn` |
|
||||||
| `RegisterResultFn` | Trait for registering fallible functions returning `Result<Dynamic, Box<EvalAltResult>>` | `register_result_fn` |
|
| `RegisterResultFn` | trait for registering fallible functions returning `Result<Dynamic, Box<EvalAltResult>>` | `register_result_fn` |
|
||||||
| `Func` | Trait for creating Rust closures from script | `create_from_ast`, `create_from_script` |
|
| `Func` | trait for creating Rust closures from script | `create_from_ast`, `create_from_script` |
|
||||||
| `ModuleResolver` | Trait implemented by module resolution services | `resolve` |
|
| `ModuleResolver` | trait implemented by module resolution services | `resolve` |
|
||||||
|
@ -19,7 +19,7 @@ This check can be disabled via the [`unchecked`] feature for higher performance
|
|||||||
```rust
|
```rust
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
|
|
||||||
engine.set_max_array_size(500); // allow arrays only up to 500 items
|
engine.set_max_array_size(500); // allow arrays only up to 500 items
|
||||||
|
|
||||||
engine.set_max_array_size(0); // allow unlimited arrays
|
engine.set_max_array_size(0); // allow unlimited arrays
|
||||||
```
|
```
|
||||||
|
@ -5,17 +5,17 @@ Rust Examples
|
|||||||
|
|
||||||
A number of examples can be found in the `examples` directory:
|
A number of examples can be found in the `examples` directory:
|
||||||
|
|
||||||
| Example | Description |
|
| Example | Description |
|
||||||
| ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [`arrays_and_structs`]({{repoTree}}/examples/arrays_and_structs.rs) | Shows how to register a custom Rust type and using [arrays] on it. |
|
| [`arrays_and_structs`]({{repoTree}}/examples/arrays_and_structs.rs) | shows how to register a custom Rust type and using [arrays] on it |
|
||||||
| [`custom_types_and_methods`]({{repoTree}}/examples/custom_types_and_methods.rs) | Shows how to register a custom Rust type and methods for it. |
|
| [`custom_types_and_methods`]({{repoTree}}/examples/custom_types_and_methods.rs) | shows how to register a custom Rust type and methods for it |
|
||||||
| [`hello`]({{repoTree}}/examples/hello.rs) | Simple example that evaluates an expression and prints the result. |
|
| [`hello`]({{repoTree}}/examples/hello.rs) | simple example that evaluates an expression and prints the result |
|
||||||
| [`reuse_scope`]({{repoTree}}/examples/reuse_scope.rs) | Evaluates two pieces of code in separate runs, but using a common [`Scope`]. |
|
| [`reuse_scope`]({{repoTree}}/examples/reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common [`Scope`] |
|
||||||
| [`rhai_runner`]({{repoTree}}/examples/rhai_runner.rs) | Runs each filename passed to it as a Rhai script. |
|
| [`rhai_runner`]({{repoTree}}/examples/rhai_runner.rs) | runs each filename passed to it as a Rhai script |
|
||||||
| [`serde`]({{repoTree}}/examples/serde.rs) | Example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde).<br/>The [`serde`] feature is required to run. |
|
| [`serde`]({{repoTree}}/examples/serde.rs) | example to serialize and deserialize Rust types with [`serde`](https://crates.io/crates/serde).<br/>The [`serde`] feature is required to run |
|
||||||
| [`simple_fn`]({{repoTree}}/examples/simple_fn.rs) | Shows how to register a simple function. |
|
| [`simple_fn`]({{repoTree}}/examples/simple_fn.rs) | shows how to register a simple function |
|
||||||
| [`strings`]({{repoTree}}/examples/strings.rs) | Shows different ways to register functions taking string arguments. |
|
| [`strings`]({{repoTree}}/examples/strings.rs) | shows different ways to register functions taking string arguments |
|
||||||
| [`repl`]({{repoTree}}/examples/repl.rs) | A simple REPL, interactively evaluate statements from stdin. |
|
| [`repl`]({{repoTree}}/examples/repl.rs) | a simple REPL, interactively evaluate statements from stdin |
|
||||||
|
|
||||||
The `repl` example is a particularly good one as it allows one to interactively try out Rhai's
|
The `repl` example is a particularly good one as it allows one to interactively try out Rhai's
|
||||||
language features in a standard REPL (**R**ead-**E**val-**P**rint **L**oop).
|
language features in a standard REPL (**R**ead-**E**val-**P**rint **L**oop).
|
||||||
@ -35,9 +35,9 @@ cargo run --example {example_name}
|
|||||||
|
|
||||||
To illustrate `no-std` builds, a number of sample applications are available under the `no_std` directory:
|
To illustrate `no-std` builds, a number of sample applications are available under the `no_std` directory:
|
||||||
|
|
||||||
| Sample | Description | Optimization | Allocator | Panics |
|
| Sample | Description | Optimization | Allocator | Panics |
|
||||||
| ------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | :----------: | :-----------------------------------------------: | :----: |
|
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | :----------: | :-----------------------------------------------: | :----: |
|
||||||
| [`no_std_test`]({{repoTree}}/no_std/no_std_test) | Bare-bones test application that evaluates a Rhai expression and sets the result as the return value. | Size | [`wee_alloc`](https://crates.io/crates/wee_alloc) | Abort |
|
| [`no_std_test`]({{repoTree}}/no_std/no_std_test) | bare-bones test application that evaluates a Rhai expression and sets the result as the return value | size | [`wee_alloc`](https://crates.io/crates/wee_alloc) | abort |
|
||||||
|
|
||||||
`cargo run` cannot be used to run a `no-std` sample. It must first be built:
|
`cargo run` cannot be used to run a `no-std` sample. It must first be built:
|
||||||
|
|
||||||
|
@ -10,22 +10,22 @@ There are also a number of examples scripts that showcase Rhai's features, all i
|
|||||||
|
|
||||||
| Script | Description |
|
| Script | Description |
|
||||||
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
| ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
||||||
| [`array.rhai`]({{repoTree}}/scripts/array.rhai) | [Arrays] |
|
| [`array.rhai`]({{repoTree}}/scripts/array.rhai) | [arrays] |
|
||||||
| [`assignment.rhai`]({{repoTree}}/scripts/assignment.rhai) | Variable declarations |
|
| [`assignment.rhai`]({{repoTree}}/scripts/assignment.rhai) | variable declarations |
|
||||||
| [`comments.rhai`]({{repoTree}}/scripts/comments.rhai) | Just comments |
|
| [`comments.rhai`]({{repoTree}}/scripts/comments.rhai) | just comments |
|
||||||
| [`for1.rhai`]({{repoTree}}/scripts/for1.rhai) | [`for`]({{rootUrl}}/language/for.md) loops |
|
| [`for1.rhai`]({{repoTree}}/scripts/for1.rhai) | [`for`]({{rootUrl}}/language/for.md) loops |
|
||||||
| [`for2.rhai`]({{repoTree}}/scripts/for2.rhai) | [`for`]({{rootUrl}}/language/for.md) loops on [arrays] |
|
| [`for2.rhai`]({{repoTree}}/scripts/for2.rhai) | [`for`]({{rootUrl}}/language/for.md) loops on [arrays] |
|
||||||
| [`function_decl1.rhai`]({{repoTree}}/scripts/function_decl1.rhai) | A [function] without parameters |
|
| [`function_decl1.rhai`]({{repoTree}}/scripts/function_decl1.rhai) | a [function] without parameters |
|
||||||
| [`function_decl2.rhai`]({{repoTree}}/scripts/function_decl2.rhai) | A [function] with two parameters |
|
| [`function_decl2.rhai`]({{repoTree}}/scripts/function_decl2.rhai) | a [function] with two parameters |
|
||||||
| [`function_decl3.rhai`]({{repoTree}}/scripts/function_decl3.rhai) | A [function] with many parameters |
|
| [`function_decl3.rhai`]({{repoTree}}/scripts/function_decl3.rhai) | a [function] with many parameters |
|
||||||
| [`if1.rhai`]({{repoTree}}/scripts/if1.rhai) | [`if`]({{rootUrl}}/language/if.md) example |
|
| [`if1.rhai`]({{repoTree}}/scripts/if1.rhai) | [`if`]({{rootUrl}}/language/if.md) example |
|
||||||
| [`loop.rhai`]({{repoTree}}/scripts/loop.rhai) | Count-down [`loop`]({{rootUrl}}/language/loop.md) in Rhai, emulating a `do` .. `while` loop |
|
| [`loop.rhai`]({{repoTree}}/scripts/loop.rhai) | count-down [`loop`]({{rootUrl}}/language/loop.md) in Rhai, emulating a `do` .. `while` loop |
|
||||||
| [`oop.rhai`]({{repoTree}}/scripts/oop.rhai) | Simulate [object-oriented programming (OOP)][OOP] with [closures] |
|
| [`oop.rhai`]({{repoTree}}/scripts/oop.rhai) | simulate [object-oriented programming (OOP)][OOP] with [closures] |
|
||||||
| [`op1.rhai`]({{repoTree}}/scripts/op1.rhai) | Just simple addition |
|
| [`op1.rhai`]({{repoTree}}/scripts/op1.rhai) | just simple addition |
|
||||||
| [`op2.rhai`]({{repoTree}}/scripts/op2.rhai) | Simple addition and multiplication |
|
| [`op2.rhai`]({{repoTree}}/scripts/op2.rhai) | simple addition and multiplication |
|
||||||
| [`op3.rhai`]({{repoTree}}/scripts/op3.rhai) | Change evaluation order with parenthesis |
|
| [`op3.rhai`]({{repoTree}}/scripts/op3.rhai) | change evaluation order with parenthesis |
|
||||||
| [`string.rhai`]({{repoTree}}/scripts/string.rhai) | [String] operations |
|
| [`string.rhai`]({{repoTree}}/scripts/string.rhai) | [string] operations |
|
||||||
| [`strings_map.rhai`]({{repoTree}}/scripts/strings_map.rhai) | [String] and [object map] operations |
|
| [`strings_map.rhai`]({{repoTree}}/scripts/strings_map.rhai) | [string] and [object map] operations |
|
||||||
| [`while.rhai`]({{repoTree}}/scripts/while.rhai) | [`while`]({{rootUrl}}/language/while.md) loop |
|
| [`while.rhai`]({{repoTree}}/scripts/while.rhai) | [`while`]({{rootUrl}}/language/while.md) loop |
|
||||||
|
|
||||||
|
|
||||||
@ -34,12 +34,12 @@ Benchmark Scripts
|
|||||||
|
|
||||||
The following scripts are for benchmarking the speed of Rhai:
|
The following scripts are for benchmarking the speed of Rhai:
|
||||||
|
|
||||||
| Scripts | Description |
|
| Scripts | Description |
|
||||||
| --------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
| --------------------------------------------------------- | -------------------------------------------------------------------------------------- |
|
||||||
| [`speed_test.rhai`]({{repoTree}}/scripts/speed_test.rhai) | A simple application to measure the speed of Rhai's interpreter (1 million iterations). |
|
| [`speed_test.rhai`]({{repoTree}}/scripts/speed_test.rhai) | a simple application to measure the speed of Rhai's interpreter (1 million iterations) |
|
||||||
| [`primes.rhai`]({{repoTree}}/scripts/primes.rhai) | Use Sieve of Eratosthenes to find all primes smaller than a limit. |
|
| [`primes.rhai`]({{repoTree}}/scripts/primes.rhai) | use Sieve of Eratosthenes to find all primes smaller than a limit |
|
||||||
| [`fibonacci.rhai`]({{repoTree}}/scripts/fibonacci.rhai) | Calculate the n-th Fibonacci number using a really dumb algorithm. |
|
| [`fibonacci.rhai`]({{repoTree}}/scripts/fibonacci.rhai) | calculate the n-th Fibonacci number using a really dumb algorithm |
|
||||||
| [`mat_mul.rhai`]({{repoTree}}/scripts/mat_mul.rhai) | Matrix multiplication test to measure the speed of multi-dimensional array access. |
|
| [`mat_mul.rhai`]({{repoTree}}/scripts/mat_mul.rhai) | matrix multiplication test to measure the speed of multi-dimensional array access |
|
||||||
|
|
||||||
|
|
||||||
Running Example Scripts
|
Running Example Scripts
|
||||||
|
@ -11,23 +11,23 @@ Notice that this deviates from Rust norm where features are _additive_.
|
|||||||
Excluding unneeded functionalities can result in smaller, faster builds as well as
|
Excluding unneeded functionalities can result in smaller, faster builds as well as
|
||||||
more control over what a script can (or cannot) do.
|
more control over what a script can (or cannot) do.
|
||||||
|
|
||||||
| Feature | Additive? | Description |
|
| Feature | Additive? | Description |
|
||||||
| ------------------- | :-------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------- | :-------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `unchecked` | No | Disable arithmetic checking (such as over-flows and division by zero), call stack depth limit, operations count limit and modules loading limit.<br/>Beware that a bad script may panic the entire system! |
|
| `unchecked` | no | disables arithmetic checking (such as over-flows and division by zero), call stack depth limit, operations count limit and modules loading limit.<br/>Beware that a bad script may panic the entire system! |
|
||||||
| `sync` | No | Restrict all values types to those that are `Send + Sync`. Under this feature, all Rhai types, including [`Engine`], [`Scope`] and [`AST`], are all `Send + Sync`. |
|
| `sync` | no | restricts all values types to those that are `Send + Sync`. Under this feature, all Rhai types, including [`Engine`], [`Scope`] and [`AST`], are all `Send + Sync` |
|
||||||
| `no_optimize` | No | Disable [script optimization]. |
|
| `no_optimize` | no | disables [script optimization] |
|
||||||
| `no_float` | No | Disable floating-point numbers and math. |
|
| `no_float` | no | disables floating-point numbers and math |
|
||||||
| `only_i32` | No | Set the system integer type to `i32` and disable all other integer types. `INT` is set to `i32`. |
|
| `only_i32` | no | sets the system integer type to `i32` and disable all other integer types. `INT` is set to `i32` |
|
||||||
| `only_i64` | No | Set the system integer type to `i64` and disable all other integer types. `INT` is set to `i64`. |
|
| `only_i64` | no | sets the system integer type to `i64` and disable all other integer types. `INT` is set to `i64` |
|
||||||
| `no_index` | No | Disable [arrays] and indexing features. |
|
| `no_index` | no | disables [arrays] and indexing features |
|
||||||
| `no_object` | No | Disable support for [custom types] and [object maps]. |
|
| `no_object` | no | disables support for [custom types] and [object maps] |
|
||||||
| `no_function` | No | Disable script-defined [functions]. |
|
| `no_function` | no | disables script-defined [functions] |
|
||||||
| `no_module` | No | Disable loading external [modules]. |
|
| `no_module` | no | disables loading external [modules] |
|
||||||
| `no_closure` | No | Disable [capturing][automatic currying] external variables in [anonymous functions] to simulate _closures_, or [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls. |
|
| `no_closure` | no | disables [capturing][automatic currying] external variables in [anonymous functions] to simulate _closures_, or [capturing the calling scope]({{rootUrl}}/language/fn-capture.md) in function calls |
|
||||||
| `no_std` | No | Build for `no-std` (implies `no_closure`). Notice that additional dependencies will be pulled in to replace `std` features. |
|
| `no_std` | no | builds for `no-std` (implies `no_closure`). Notice that additional dependencies will be pulled in to replace `std` features |
|
||||||
| `serde` | Yes | Enable serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies. |
|
| `serde` | yes | enables serialization/deserialization via `serde`. Notice that the [`serde`](https://crates.io/crates/serde) crate will be pulled in together with its dependencies |
|
||||||
| `internals` | Yes | Expose internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version. |
|
| `internals` | yes | exposes internal data structures (e.g. [`AST`] nodes). Beware that Rhai internals are volatile and may change from version to version |
|
||||||
| `unicode-xid-ident` | No | Allow [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers. |
|
| `unicode-xid-ident` | no | allows [Unicode Standard Annex #31](http://www.unicode.org/reports/tr31/) as identifiers |
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
|
Loading…
Reference in New Issue
Block a user