Merge branch 'master' into namespace
This commit is contained in:
commit
1934811838
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rhai"
|
name = "rhai"
|
||||||
version = "0.13.0"
|
version = "0.14.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"]
|
authors = ["Jonathan Turner", "Lukáš Hozda", "Stephen Chung"]
|
||||||
description = "Embedded scripting for Rust"
|
description = "Embedded scripting for Rust"
|
||||||
|
@ -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
|
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`.
|
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
|
Installation
|
||||||
------------
|
------------
|
||||||
@ -39,7 +39,7 @@ Install the Rhai crate by adding this line to `dependencies`:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rhai = "0.13.0"
|
rhai = "0.14.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
Use the latest released crate version on [`crates.io`](https::/crates.io/crates/rhai/):
|
Use the latest released crate version on [`crates.io`](https::/crates.io/crates/rhai/):
|
||||||
|
@ -221,11 +221,11 @@ impl Stack {
|
|||||||
})
|
})
|
||||||
.and_then(|(i, _)| NonZeroUsize::new(i + 1))
|
.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`,
|
/// The return value is the offset to be deducted from `Stack::len`,
|
||||||
/// i.e. the top element of the `Stack` is offset 1.
|
/// i.e. the top element of the `Stack` is offset 1.
|
||||||
/// Return zero when the variable name is not found in the `Stack`.
|
/// 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
|
self.0
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
@ -1115,7 +1115,7 @@ fn parse_primary<'a>(
|
|||||||
modules = Some(Box::new(vec));
|
modules = Some(Box::new(vec));
|
||||||
|
|
||||||
let root = modules.as_ref().unwrap().iter().next().unwrap();
|
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)
|
Expr::Variable(Box::new(id2), modules, index, pos2)
|
||||||
@ -1831,12 +1831,23 @@ fn parse_let<'a>(
|
|||||||
ScopeEntryType::Constant => {
|
ScopeEntryType::Constant => {
|
||||||
Err(PERR::ForbiddenConstantExpr(name).into_err(init_value.position()))
|
Err(PERR::ForbiddenConstantExpr(name).into_err(init_value.position()))
|
||||||
}
|
}
|
||||||
// Variable cannot be a sub-scope
|
// Variable cannot be a module
|
||||||
ScopeEntryType::Module => unreachable!(),
|
ScopeEntryType::Module => unreachable!(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// let name
|
// 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!(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user