From 75a8a4d4e337ca4ca3e38ba08393dcdc6003631e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 8 Jul 2021 14:09:31 +0800 Subject: [PATCH] Enable json command in REPL. --- Cargo.toml | 4 ++-- no_std/no_std_repl/README.md | 12 +++++++++--- no_std/no_std_test/README.md | 12 +++++++++--- src/bin/rhai-repl.rs | 21 ++++++++++++--------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51d93977..9ad99208 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ no_float = [] # no floating-point f32_float = [] # set FLOAT=f32 only_i32 = [] # set INT=i32 (useful for 32-bit systems) only_i64 = [] # set INT=i64 (default) and disable support for all other integer types -decimal = ["rust_decimal/std"] # add the Decimal number type +decimal = ["rust_decimal"] # add the Decimal number type no_index = [] # no arrays and indexing no_object = [] # no custom objects no_function = ["no_closure"] # no script-defined functions (meaning no closures) @@ -40,7 +40,7 @@ no_closure = [] # no automatic sharing and capture of anonymous no_module = [] # no modules internals = [] # expose internal data structures unicode-xid-ident = ["unicode-xid"] # allow Unicode Standard Annex #31 for identifiers. -metadata = ["serde_json", "rhai_codegen/metadata"] # enable exporting functions metadata +metadata = ["serde", "serde_json", "rhai_codegen/metadata"] # enable exporting functions metadata no_std = ["no-std-compat", "num-traits/libm", "core-error", "libm", "ahash/compile-time-rng"] diff --git a/no_std/no_std_repl/README.md b/no_std/no_std_repl/README.md index 521111d8..c7ea3ce5 100644 --- a/no_std/no_std_repl/README.md +++ b/no_std/no_std_repl/README.md @@ -6,15 +6,21 @@ This sample application is the same version as the `rhai-repl` tool, compiled fo [`wee_alloc`](https://crates.io/crates/wee_alloc) is used as the allocator. -To Compile ----------- +To Build +-------- The nightly compiler is required: +```bash +cargo +nightly build --release +``` + +A specific profile can also be used: + ```bash cargo +nightly build --profile unix -Z unstable-options ``` -Available profiles are: `unix`, `windows` and `macos`. +Three profiles are defined: `unix`, `windows` and `macos`. The release build is optimized for size. It can be changed to optimize on speed instead. diff --git a/no_std/no_std_test/README.md b/no_std/no_std_test/README.md index 1c89b11f..042e15c0 100644 --- a/no_std/no_std_test/README.md +++ b/no_std/no_std_test/README.md @@ -6,15 +6,21 @@ This sample application is a bare-bones `no-std` build for testing. [`wee_alloc`](https://crates.io/crates/wee_alloc) is used as the allocator. -To Compile ----------- +To Build +-------- The nightly compiler is required: +```bash +cargo +nightly build --release +``` + +A specific profile can also be used: + ```bash cargo +nightly build --profile unix -Z unstable-options ``` -Available profiles are: `unix`, `windows` and `macos`. +Three profiles are defined: `unix`, `windows` and `macos`. The release build is optimized for size. It can be changed to optimize on speed instead. diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index a4af261f..2a11f76f 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -48,6 +48,8 @@ fn print_help() { println!("scope => print all variables in the scope"); #[cfg(feature = "metadata")] println!("functions => print all functions defined"); + #[cfg(feature = "metadata")] + println!("json => output all functions in JSON format"); println!("ast => print the last AST (optimized)"); println!("astu => print the last raw, un-optimized AST"); println!(r"end a line with '\' to continue to the next line."); @@ -247,15 +249,16 @@ fn main() { println!(); continue; } - // "json" => { - // println!( - // "{}", - // engine - // .gen_fn_metadata_with_ast_to_json(&main_ast, true) - // .unwrap() - // ); - // continue; - // } + #[cfg(feature = "metadata")] + "json" => { + println!( + "{}", + engine + .gen_fn_metadata_with_ast_to_json(&main_ast, true) + .unwrap() + ); + continue; + } _ => (), }