Add comments to examples.

This commit is contained in:
Stephen Chung 2022-02-12 12:41:04 +08:00
parent 2caf686e8a
commit 3f8f0b250f
9 changed files with 20 additions and 2 deletions

View File

@ -7,6 +7,7 @@ Standard Examples
| Example | Description |
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays |
| [`callback`](callback.rs) | shows how to store a Rhai closure and call it later within Rust |
| [`custom_types_and_methods`](custom_types_and_methods.rs) | shows how to register a Rust type and methods/getters/setters for it |
| [`hello`](hello.rs) | simple example that evaluates an expression and prints the result |
| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` |

View File

@ -1,3 +1,5 @@
//! An example showing how to register a Rust type and use it with arrays.
use rhai::{Engine, EvalAltResult};
#[cfg(not(feature = "no_index"))]

View File

@ -1,3 +1,5 @@
//! An example showing how to register a Rust type and methods/getters/setters for it.
use rhai::{Engine, EvalAltResult};
#[cfg(not(feature = "no_object"))]

View File

@ -1,3 +1,5 @@
//! A simple example that evaluates an expression and prints the result.
use rhai::{Engine, EvalAltResult};
fn main() -> Result<(), Box<EvalAltResult>> {

View File

@ -1,3 +1,5 @@
//! An example that evaluates two pieces of code in separate runs, but using a common `Scope`.
use rhai::{Engine, EvalAltResult, Scope};
fn main() -> Result<(), Box<EvalAltResult>> {

View File

@ -1,3 +1,5 @@
//! An example to serialize and deserialize Rust types.
#[cfg(any(not(feature = "serde"), feature = "no_object"))]
fn main() {
println!("This example requires the 'serde' feature to run.");

View File

@ -1,3 +1,5 @@
//! An example showing how to register a simple Rust function.
use rhai::{Engine, EvalAltResult};
fn add(x: i64, y: i64) -> i64 {

View File

@ -1,5 +1,6 @@
///! This example registers a variety of functions that operate on strings.
///! Remember to use `ImmutableString` or `&str` instead of `String` as parameters.
//! An example that registers a variety of functions that operate on strings.
//! Remember to use `ImmutableString` or `&str` instead of `String` as parameters.
use rhai::{Engine, EvalAltResult, ImmutableString, Scope};
use std::io::{stdin, stdout, Write};
@ -12,6 +13,7 @@ fn trim_string(s: &mut ImmutableString) {
/// Notice this is different from the built-in Rhai 'len' function for strings
/// which counts the actual number of Unicode _characters_ in a string.
///
/// This version simply counts the number of _bytes_ in the UTF-8 representation.
///
/// This version uses `&str`.

View File

@ -1,3 +1,6 @@
//! An advanced example showing how to communicate with an `Engine` running in a separate thread via
//! an MPSC channel.
use rhai::Engine;
#[cfg(feature = "sync")]