Update comments with links.

This commit is contained in:
Stephen Chung
2020-11-20 16:52:28 +08:00
parent 2afcecc6ba
commit 783803ec46
40 changed files with 698 additions and 644 deletions

View File

@@ -2,7 +2,7 @@
use crate::plugin::*;
use crate::stdlib::{format, string::String};
use crate::{def_package, EvalAltResult, INT, NO_POS};
use crate::{def_package, EvalAltResult, Position, INT};
#[cfg(not(feature = "no_float"))]
use crate::FLOAT;
@@ -13,7 +13,7 @@ use num_traits::float::Float;
#[inline(always)]
pub fn make_err(msg: impl Into<String>) -> Box<EvalAltResult> {
EvalAltResult::ErrorArithmetic(msg.into(), NO_POS).into()
EvalAltResult::ErrorArithmetic(msg.into(), Position::NONE).into()
}
macro_rules! gen_arithmetic_functions {

View File

@@ -5,8 +5,8 @@ use crate::engine::{OP_EQUALS, TYPICAL_ARRAY_SIZE};
use crate::plugin::*;
use crate::stdlib::{any::TypeId, boxed::Box, cmp::max, cmp::Ordering, string::ToString};
use crate::{
def_package, Array, Dynamic, EvalAltResult, FnPtr, ImmutableString, NativeCallContext, INT,
NO_POS,
def_package, Array, Dynamic, EvalAltResult, FnPtr, ImmutableString, NativeCallContext,
Position, INT,
};
#[cfg(not(feature = "no_object"))]
@@ -42,7 +42,7 @@ macro_rules! gen_array_functions {
#[cfg(not(feature = "unchecked"))]
if _ctx.engine().max_array_size() > 0 && len > 0 && (len as usize) > _ctx.engine().max_array_size() {
return EvalAltResult::ErrorDataTooLarge(
"Size of array".to_string(), NO_POS
"Size of array".to_string(), Position::NONE
).into();
}
@@ -215,7 +215,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"map".to_string(),
err,
NO_POS,
Position::NONE,
))
})?,
);
@@ -246,7 +246,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"filter".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -279,7 +279,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"index_of".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -312,7 +312,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"some".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -345,7 +345,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"all".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -380,7 +380,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
}
@@ -398,7 +398,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
@@ -417,7 +417,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
}
@@ -447,7 +447,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce_rev".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
}
@@ -465,7 +465,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce_rev".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
@@ -484,7 +484,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"reduce_rev".to_string(),
err,
NO_POS,
Position::NONE,
))
})?;
}
@@ -554,7 +554,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"drain".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -613,7 +613,7 @@ mod array_functions {
Box::new(EvalAltResult::ErrorInFunctionCall(
"retain".to_string(),
err,
NO_POS,
Position::NONE,
))
})?
.as_bool()
@@ -665,7 +665,7 @@ mod array_functions {
for (a1, a2) in arr1.iter_mut().zip(arr2.iter_mut()) {
let equals = ctx
.call_fn_dynamic_raw(OP_EQUALS, true, false, &mut [a1, a2], def_value.clone())
.call_fn_dynamic_raw(OP_EQUALS, true, false, &mut [a1, a2], def_value.as_ref())
.map(|v| v.as_bool().unwrap_or(false))?;
if !equals {

View File

@@ -61,7 +61,7 @@ mod map_functions {
for (m1, v1) in map1.iter_mut() {
if let Some(v2) = map2.get_mut(m1) {
let equals = ctx
.call_fn_dynamic_raw(OP_EQUALS, true, false, &mut [v1, v2], def_value.clone())
.call_fn_dynamic_raw(OP_EQUALS, true, false, &mut [v1, v2], def_value.as_ref())
.map(|v| v.as_bool().unwrap_or(false))?;
if !equals {

View File

@@ -1,7 +1,7 @@
#![allow(non_snake_case)]
use crate::plugin::*;
use crate::{def_package, INT, NO_POS};
use crate::{def_package, Position, INT};
#[cfg(not(feature = "no_float"))]
use crate::FLOAT;
@@ -83,8 +83,11 @@ mod int_functions {
#[rhai_fn(name = "parse_int", return_raw)]
pub fn parse_int_radix(s: &str, radix: INT) -> Result<Dynamic, Box<EvalAltResult>> {
if radix < 2 || radix > 36 {
return EvalAltResult::ErrorArithmetic(format!("Invalid radix: '{}'", radix), NO_POS)
.into();
return EvalAltResult::ErrorArithmetic(
format!("Invalid radix: '{}'", radix),
Position::NONE,
)
.into();
}
INT::from_str_radix(s.trim(), radix as u32)
@@ -92,7 +95,7 @@ mod int_functions {
.map_err(|err| {
EvalAltResult::ErrorArithmetic(
format!("Error parsing integer number '{}': {}", s, err),
NO_POS,
Position::NONE,
)
.into()
})
@@ -201,8 +204,11 @@ mod float_functions {
#[rhai_fn(name = "to_int", return_raw)]
pub fn f32_to_int(x: f32) -> Result<Dynamic, Box<EvalAltResult>> {
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f32) {
EvalAltResult::ErrorArithmetic(format!("Integer overflow: to_int({})", x), NO_POS)
.into()
EvalAltResult::ErrorArithmetic(
format!("Integer overflow: to_int({})", x),
Position::NONE,
)
.into()
} else {
Ok((x.trunc() as INT).into())
}
@@ -210,8 +216,11 @@ mod float_functions {
#[rhai_fn(name = "to_int", return_raw)]
pub fn f64_to_int(x: f64) -> Result<Dynamic, Box<EvalAltResult>> {
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {
EvalAltResult::ErrorArithmetic(format!("Integer overflow: to_int({})", x), NO_POS)
.into()
EvalAltResult::ErrorArithmetic(
format!("Integer overflow: to_int({})", x),
Position::NONE,
)
.into()
} else {
Ok((x.trunc() as INT).into())
}
@@ -224,7 +233,7 @@ mod float_functions {
.map_err(|err| {
EvalAltResult::ErrorArithmetic(
format!("Error parsing floating-point number '{}': {}", s, err),
NO_POS,
Position::NONE,
)
.into()
})

View File

@@ -44,16 +44,16 @@ pub trait Package {
fn get(&self) -> PackageLibrary;
}
/// A sharable `Module` to facilitate sharing library instances.
/// A sharable [`Module`][crate::Module] to facilitate sharing library instances.
pub type PackageLibrary = Shared<Module>;
/// Type containing a collection of `PackageLibrary` instances.
/// Type containing a collection of [`PackageLibrary`] instances.
/// All function and type iterator keys in the loaded packages are indexed for fast access.
#[derive(Debug, Clone, Default)]
pub(crate) struct PackagesCollection(Option<StaticVec<PackageLibrary>>);
impl PackagesCollection {
/// Add a `PackageLibrary` into the `PackagesCollection`.
/// Add a [`PackageLibrary`] into the [`PackagesCollection`].
///
/// Packages are searched in reverse order.
pub fn add(&mut self, package: PackageLibrary) {
@@ -63,7 +63,7 @@ impl PackagesCollection {
// Later packages override previous ones.
self.0.as_mut().unwrap().insert(0, package);
}
/// Does the specified function hash key exist in the `PackagesCollection`?
/// Does the specified function hash key exist in the [`PackagesCollection`]?
#[allow(dead_code)]
pub fn contains_fn(&self, hash: u64) -> bool {
self.0
@@ -76,14 +76,14 @@ impl PackagesCollection {
.as_ref()
.and_then(|x| x.iter().find_map(|p| p.get_fn(hash, false)))
}
/// Does the specified TypeId iterator exist in the `PackagesCollection`?
/// Does the specified [`TypeId`] iterator exist in the [`PackagesCollection`]?
#[allow(dead_code)]
pub fn contains_iter(&self, id: TypeId) -> bool {
self.0
.as_ref()
.map_or(false, |x| x.iter().any(|p| p.contains_iter(id)))
}
/// Get the specified TypeId iterator.
/// Get the specified [`TypeId`] iterator.
pub fn get_iter(&self, id: TypeId) -> Option<IteratorFn> {
self.0
.as_ref()
@@ -95,7 +95,7 @@ impl PackagesCollection {
/// and register functions into it.
///
/// Functions can be added to the package using the standard module methods such as
/// `set_fn_2`, `set_fn_3_mut`, `set_fn_0` etc.
/// [`set_fn_2`][Module::set_fn_2], [`set_fn_3_mut`][Module::set_fn_3_mut], [`set_fn_0`][Module::set_fn_0] etc.
///
/// # Example
///

View File

@@ -252,7 +252,7 @@ mod string_functions {
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
crate::Position::NONE,
)
.into();
}
@@ -272,7 +272,7 @@ mod string_functions {
{
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
crate::Position::NONE,
)
.into();
}
@@ -293,7 +293,7 @@ mod string_functions {
if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() {
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
crate::Position::NONE,
)
.into();
}
@@ -320,7 +320,7 @@ mod string_functions {
{
return crate::EvalAltResult::ErrorDataTooLarge(
"Length of string".to_string(),
crate::NO_POS,
crate::Position::NONE,
)
.into();
}