Merge branch 'master' into namespace

This commit is contained in:
Stephen Chung 2020-05-06 22:58:15 +08:00
commit 1934811838
3 changed files with 19 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "rhai"
version = "0.13.0"
version = "0.14.1"
edition = "2018"
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"]
description = "Embedded scripting for Rust"

View File

@ -30,7 +30,7 @@ Rhai's current features set:
to do checked arithmetic operations); for [`no-std`](#optional-features) builds, a number of additional dependencies are
pulled in to provide for functionalities that used to be in `std`.
**Note:** Currently, the version is 0.13.0, so the language and API's may change before they stabilize.
**Note:** Currently, the version is 0.14.1, so the language and API's may change before they stabilize.
Installation
------------
@ -39,7 +39,7 @@ Install the Rhai crate by adding this line to `dependencies`:
```toml
[dependencies]
rhai = "0.13.0"
rhai = "0.14.1"
```
Use the latest released crate version on [`crates.io`](https::/crates.io/crates/rhai/):

View File

@ -221,11 +221,11 @@ impl Stack {
})
.and_then(|(i, _)| NonZeroUsize::new(i + 1))
}
/// Find a sub-scope by name in the `Stack`, searching in reverse.
/// Find a module by name in the `Stack`, searching in reverse.
/// The return value is the offset to be deducted from `Stack::len`,
/// i.e. the top element of the `Stack` is offset 1.
/// Return zero when the variable name is not found in the `Stack`.
pub fn find_sub_scope(&self, name: &str) -> Option<NonZeroUsize> {
pub fn find_module(&self, name: &str) -> Option<NonZeroUsize> {
self.0
.iter()
.rev()
@ -1115,7 +1115,7 @@ fn parse_primary<'a>(
modules = Some(Box::new(vec));
let root = modules.as_ref().unwrap().iter().next().unwrap();
index = stack.find_sub_scope(&root.0);
index = stack.find_module(&root.0);
}
Expr::Variable(Box::new(id2), modules, index, pos2)
@ -1831,12 +1831,23 @@ fn parse_let<'a>(
ScopeEntryType::Constant => {
Err(PERR::ForbiddenConstantExpr(name).into_err(init_value.position()))
}
// Variable cannot be a sub-scope
// Variable cannot be a module
ScopeEntryType::Module => unreachable!(),
}
} else {
// let name
Ok(Stmt::Let(Box::new(name), None, pos))
match var_type {
ScopeEntryType::Normal => {
stack.push((name.clone(), ScopeEntryType::Normal));
Ok(Stmt::Let(Box::new(name), None, pos))
}
ScopeEntryType::Constant => {
stack.push((name.clone(), ScopeEntryType::Constant));
Ok(Stmt::Const(Box::new(name), Box::new(Expr::Unit(pos)), pos))
}
// Variable cannot be a module
ScopeEntryType::Module => unreachable!(),
}
}
}