Add comments to examples.
This commit is contained in:
parent
2caf686e8a
commit
3f8f0b250f
@ -7,6 +7,7 @@ Standard Examples
|
|||||||
| Example | Description |
|
| Example | Description |
|
||||||
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [`arrays_and_structs`](arrays_and_structs.rs) | shows how to register a Rust type and using it with arrays |
|
| [`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 |
|
| [`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 |
|
| [`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` |
|
| [`reuse_scope`](reuse_scope.rs) | evaluates two pieces of code in separate runs, but using a common `Scope` |
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! An example showing how to register a Rust type and use it with arrays.
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult};
|
use rhai::{Engine, EvalAltResult};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! An example showing how to register a Rust type and methods/getters/setters for it.
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult};
|
use rhai::{Engine, EvalAltResult};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! A simple example that evaluates an expression and prints the result.
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult};
|
use rhai::{Engine, EvalAltResult};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<EvalAltResult>> {
|
fn main() -> Result<(), Box<EvalAltResult>> {
|
||||||
|
@ -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};
|
use rhai::{Engine, EvalAltResult, Scope};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<EvalAltResult>> {
|
fn main() -> Result<(), Box<EvalAltResult>> {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! An example to serialize and deserialize Rust types.
|
||||||
|
|
||||||
#[cfg(any(not(feature = "serde"), feature = "no_object"))]
|
#[cfg(any(not(feature = "serde"), feature = "no_object"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("This example requires the 'serde' feature to run.");
|
println!("This example requires the 'serde' feature to run.");
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//! An example showing how to register a simple Rust function.
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult};
|
use rhai::{Engine, EvalAltResult};
|
||||||
|
|
||||||
fn add(x: i64, y: i64) -> i64 {
|
fn add(x: i64, y: i64) -> i64 {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
///! This example registers a variety of functions that operate on strings.
|
//! An example that registers a variety of functions that operate on strings.
|
||||||
///! Remember to use `ImmutableString` or `&str` instead of `String` as parameters.
|
//! Remember to use `ImmutableString` or `&str` instead of `String` as parameters.
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult, ImmutableString, Scope};
|
use rhai::{Engine, EvalAltResult, ImmutableString, Scope};
|
||||||
use std::io::{stdin, stdout, Write};
|
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
|
/// Notice this is different from the built-in Rhai 'len' function for strings
|
||||||
/// which counts the actual number of Unicode _characters_ in a string.
|
/// 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 simply counts the number of _bytes_ in the UTF-8 representation.
|
||||||
///
|
///
|
||||||
/// This version uses `&str`.
|
/// This version uses `&str`.
|
||||||
|
@ -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;
|
use rhai::Engine;
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
|
Loading…
Reference in New Issue
Block a user