From 84fbcb03b3b69a99a4e6081b034d4865254afde4 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 17 Jun 2020 15:45:11 +0800 Subject: [PATCH] Add WASM section. --- README.md | 13 +++++++++---- src/engine.rs | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 34682ab7..cc1411a9 100644 --- a/README.md +++ b/README.md @@ -172,12 +172,17 @@ A _raw_ engine supports, out of the box, only a very [restricted set](#built-in- Selectively include other necessary functionalities by loading specific [packages] to minimize the footprint. Packages are sharable (even across threads via the [`sync`] feature), so they only have to be created once. -### Compiling to WebAssembly (WASM) +### Building to WebAssembly (WASM) -[WASM]: #compiling-to-WebAssembly-wasm +[WASM]: #building-to-WebAssembly-wasm -It is possible to use Rhai when compiling to WebAssembly (WASM), but certain features will not be available, -such as the script file API's and loading modules from external script files. +It is possible to use Rhai when compiling to WebAssembly (WASM). This yields a scripting engine (and language) +that can be run in a standard web browser. Why you would want to is another matter... as there is already +a nice, fast, complete scripting language for the the common WASM environment (i.e. a browser) - and it is called JavaScript. +But anyhow, do it because you _can_! + +When building for WASM, certain features will not be available, such as the script file API's and loading modules +from external script files. Also look into [minimal builds] to reduce generated WASM size. As of this version, a typical, full-featured Rhai scripting engine compiles to a single WASM file around 200KB gzipped. When excluding features that are diff --git a/src/engine.rs b/src/engine.rs index 9c4c65ec..21d055bd 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -6,7 +6,7 @@ use crate::error::ParseErrorType; use crate::fn_native::{CallableFunction, Callback, FnCallArgs}; use crate::module::{resolvers, Module, ModuleResolver}; use crate::optimize::OptimizationLevel; -use crate::packages::{CorePackage, Package, PackageLibrary, PackagesCollection, StandardPackage}; +use crate::packages::{Package, PackageLibrary, PackagesCollection, StandardPackage}; use crate::parser::{Expr, FnAccess, ImmutableString, ReturnType, ScriptFnDef, Stmt, AST, INT}; use crate::r#unsafe::{unsafe_cast_var_name_to_lifetime, unsafe_mut_cast_to_lifetime}; use crate::result::EvalAltResult;