Refactor wasm feature gates.
This commit is contained in:
parent
d99953c101
commit
328f6910b6
@ -20,7 +20,8 @@ impl Engine {
|
|||||||
/// This method will be removed in the next major version.
|
/// This method will be removed in the next major version.
|
||||||
#[deprecated(since = "1.1.0", note = "use `run_file` instead")]
|
#[deprecated(since = "1.1.0", note = "use `run_file` instead")]
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn consume_file(&self, path: std::path::PathBuf) -> RhaiResultOf<()> {
|
pub fn consume_file(&self, path: std::path::PathBuf) -> RhaiResultOf<()> {
|
||||||
self.run_file(path)
|
self.run_file(path)
|
||||||
@ -38,7 +39,8 @@ impl Engine {
|
|||||||
/// This method will be removed in the next major version.
|
/// This method will be removed in the next major version.
|
||||||
#[deprecated(since = "1.1.0", note = "use `run_file_with_scope` instead")]
|
#[deprecated(since = "1.1.0", note = "use `run_file_with_scope` instead")]
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn consume_file_with_scope(
|
pub fn consume_file_with_scope(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
//! Module that defines the public file-based API of [`Engine`].
|
//! Module that defines the public file-based API of [`Engine`].
|
||||||
#![cfg(not(feature = "no_std"))]
|
#![cfg(not(feature = "no_std"))]
|
||||||
#![cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#![cfg(not(target_arch = "wasm32"))]
|
||||||
|
#![cfg(not(target_arch = "wasm64"))]
|
||||||
|
|
||||||
use crate::types::dynamic::Variant;
|
use crate::types::dynamic::Variant;
|
||||||
use crate::{Engine, RhaiResultOf, Scope, AST, ERR};
|
use crate::{Engine, RhaiResultOf, Scope, AST, ERR};
|
||||||
@ -165,8 +166,6 @@ impl Engine {
|
|||||||
/// Evaluate a file, returning any error (if any).
|
/// Evaluate a file, returning any error (if any).
|
||||||
///
|
///
|
||||||
/// Not available under `no_std` or `WASM`.
|
/// Not available under `no_std` or `WASM`.
|
||||||
#[cfg(not(feature = "no_std"))]
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn run_file(&self, path: std::path::PathBuf) -> RhaiResultOf<()> {
|
pub fn run_file(&self, path: std::path::PathBuf) -> RhaiResultOf<()> {
|
||||||
Self::read_file(path).and_then(|contents| self.run(&contents))
|
Self::read_file(path).and_then(|contents| self.run(&contents))
|
||||||
@ -180,8 +179,6 @@ impl Engine {
|
|||||||
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
/// If not [`OptimizationLevel::None`][crate::OptimizationLevel::None], constants defined within
|
||||||
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
/// the scope are propagated throughout the script _including_ functions. This allows functions
|
||||||
/// to be optimized based on dynamic global constants.
|
/// to be optimized based on dynamic global constants.
|
||||||
#[cfg(not(feature = "no_std"))]
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn run_file_with_scope(
|
pub fn run_file_with_scope(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
//! Module defining script options.
|
//! Module defining script options.
|
||||||
|
|
||||||
|
use std::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, Not, Sub, SubAssign};
|
||||||
|
#[cfg(feature = "no_std")]
|
||||||
|
use std::prelude::v1::*;
|
||||||
|
|
||||||
/// A type representing the access mode of a function.
|
/// A type representing the access mode of a function.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
pub enum FnAccess {
|
pub enum FnAccess {
|
||||||
@ -9,10 +13,6 @@ pub enum FnAccess {
|
|||||||
Private,
|
Private,
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::ops::{Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, Not, Sub, SubAssign};
|
|
||||||
#[cfg(feature = "no_std")]
|
|
||||||
use std::prelude::v1::*;
|
|
||||||
|
|
||||||
/// A type that holds a configuration option with bit-flags.
|
/// A type that holds a configuration option with bit-flags.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Hash, Default)]
|
#[derive(PartialEq, Eq, Copy, Clone, Hash, Default)]
|
||||||
|
@ -352,8 +352,13 @@ impl<'a> Target<'a> {
|
|||||||
/// Convert a shared or reference `Target` into a target with an owned value.
|
/// Convert a shared or reference `Target` into a target with an owned value.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn into_owned(self) -> Target<'static> {
|
pub fn into_owned(self) -> Self {
|
||||||
self.take_or_clone().into()
|
match self {
|
||||||
|
Self::RefMut(r) => Self::TempValue(r.clone()),
|
||||||
|
#[cfg(not(feature = "no_closure"))]
|
||||||
|
Self::SharedValue { value, .. } => Self::TempValue(value),
|
||||||
|
_ => self,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Propagate a changed value back to the original source.
|
/// Propagate a changed value back to the original source.
|
||||||
/// This has no effect for direct references.
|
/// This has no effect for direct references.
|
||||||
@ -1073,7 +1078,8 @@ pub fn is_anonymous_fn(fn_name: &str) -> bool {
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn print_to_stdout(s: &str) {
|
fn print_to_stdout(s: &str) {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
println!("{}", s);
|
println!("{}", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,7 +1088,8 @@ fn print_to_stdout(s: &str) {
|
|||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn debug_to_stdout(s: &str, source: Option<&str>, pos: Position) {
|
fn debug_to_stdout(s: &str, source: Option<&str>, pos: Position) {
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
if let Some(source) = source {
|
if let Some(source) = source {
|
||||||
println!("{}{:?} | {}", source, pos, s);
|
println!("{}{:?} | {}", source, pos, s);
|
||||||
} else if pos.is_none() {
|
} else if pos.is_none() {
|
||||||
@ -1102,7 +1109,8 @@ impl Engine {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
{
|
{
|
||||||
engine.module_resolver =
|
engine.module_resolver =
|
||||||
Some(Box::new(crate::module::resolvers::FileModuleResolver::new()));
|
Some(Box::new(crate::module::resolvers::FileModuleResolver::new()));
|
||||||
|
@ -25,7 +25,12 @@ const BUILTIN: &str = "data type was checked";
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn is_numeric(type_id: TypeId) -> bool {
|
fn is_numeric(type_id: TypeId) -> bool {
|
||||||
let result = type_id == TypeId::of::<u8>()
|
let result = false;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "only_i64"))]
|
||||||
|
#[cfg(not(feature = "only_i32"))]
|
||||||
|
let result = result
|
||||||
|
|| type_id == TypeId::of::<u8>()
|
||||||
|| type_id == TypeId::of::<u16>()
|
|| type_id == TypeId::of::<u16>()
|
||||||
|| type_id == TypeId::of::<u32>()
|
|| type_id == TypeId::of::<u32>()
|
||||||
|| type_id == TypeId::of::<u64>()
|
|| type_id == TypeId::of::<u64>()
|
||||||
@ -34,7 +39,10 @@ fn is_numeric(type_id: TypeId) -> bool {
|
|||||||
|| type_id == TypeId::of::<i32>()
|
|| type_id == TypeId::of::<i32>()
|
||||||
|| type_id == TypeId::of::<i64>();
|
|| type_id == TypeId::of::<i64>();
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
|
#[cfg(not(feature = "only_i32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
let result = result || type_id == TypeId::of::<u128>() || type_id == TypeId::of::<i128>();
|
let result = result || type_id == TypeId::of::<u128>() || type_id == TypeId::of::<i128>();
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
@ -1142,7 +1142,7 @@ impl Engine {
|
|||||||
} else {
|
} else {
|
||||||
// Turn it into a method call only if the object is not shared and not a simple value
|
// Turn it into a method call only if the object is not shared and not a simple value
|
||||||
is_ref_mut = true;
|
is_ref_mut = true;
|
||||||
let obj_ref = target.take_ref().expect("reference");
|
let obj_ref = target.take_ref().expect("ref");
|
||||||
args.push(obj_ref);
|
args.push(obj_ref);
|
||||||
args.extend(arg_values.iter_mut());
|
args.extend(arg_values.iter_mut());
|
||||||
}
|
}
|
||||||
@ -1217,7 +1217,7 @@ impl Engine {
|
|||||||
// Turn it into a method call only if the object is not shared and not a simple value
|
// Turn it into a method call only if the object is not shared and not a simple value
|
||||||
let (first, rest) = arg_values.split_first_mut().expect("not empty");
|
let (first, rest) = arg_values.split_first_mut().expect("not empty");
|
||||||
first_arg_value = Some(first);
|
first_arg_value = Some(first);
|
||||||
let obj_ref = target.take_ref().expect("reference");
|
let obj_ref = target.take_ref().expect("ref");
|
||||||
args.push(obj_ref);
|
args.push(obj_ref);
|
||||||
args.extend(rest.iter_mut());
|
args.extend(rest.iter_mut());
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@
|
|||||||
//! engine.register_fn("compute", compute_something);
|
//! engine.register_fn("compute", compute_something);
|
||||||
//!
|
//!
|
||||||
//! # #[cfg(not(feature = "no_std"))]
|
//! # #[cfg(not(feature = "no_std"))]
|
||||||
//! # #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
//! # #[cfg(not(target_arch = "wasm32"))]
|
||||||
|
//! # #[cfg(not(target_arch = "wasm64"))]
|
||||||
//! // Evaluate the script, expecting a 'bool' result
|
//! // Evaluate the script, expecting a 'bool' result
|
||||||
//! let result = engine.eval_file::<bool>("my_script.rhai".into())?;
|
//! let result = engine.eval_file::<bool>("my_script.rhai".into())?;
|
||||||
//!
|
//!
|
||||||
@ -366,11 +367,13 @@ compile_error!("`stdweb` cannot be used with `no-std`");
|
|||||||
#[cfg(feature = "no_std")]
|
#[cfg(feature = "no_std")]
|
||||||
compile_error!("`no_std` cannot be used for WASM target");
|
compile_error!("`no_std` cannot be used for WASM target");
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
#[cfg(feature = "wasm-bindgen")]
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
compile_error!("`wasm-bindgen` cannot be used for non-WASM target");
|
compile_error!("`wasm-bindgen` cannot be used for non-WASM target");
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
#[cfg(feature = "stdweb")]
|
#[cfg(feature = "stdweb")]
|
||||||
compile_error!("`stdweb` cannot be used non-WASM target");
|
compile_error!("`stdweb` cannot be used non-WASM target");
|
||||||
|
|
||||||
|
@ -702,15 +702,11 @@ impl Module {
|
|||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.update_fn_metadata(hash_fn, arg_names);
|
self.update_fn_metadata(hash_fn, arg_names);
|
||||||
|
|
||||||
if !comments.as_ref().is_empty() {
|
let comments = comments.as_ref();
|
||||||
|
|
||||||
|
if !comments.is_empty() {
|
||||||
let f = self.functions.get_mut(&hash_fn).expect("exists");
|
let f = self.functions.get_mut(&hash_fn).expect("exists");
|
||||||
f.comments = Some(
|
f.comments = Some(comments.iter().map(|s| s.as_ref().into()).collect());
|
||||||
comments
|
|
||||||
.as_ref()
|
|
||||||
.iter()
|
|
||||||
.map(|s| s.as_ref().into())
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -869,15 +865,11 @@ impl Module {
|
|||||||
) -> u64 {
|
) -> u64 {
|
||||||
let hash = self.set_fn(name, namespace, access, arg_names, arg_types, func);
|
let hash = self.set_fn(name, namespace, access, arg_names, arg_types, func);
|
||||||
|
|
||||||
if !comments.as_ref().is_empty() {
|
let comments = comments.as_ref();
|
||||||
|
|
||||||
|
if !comments.is_empty() {
|
||||||
let f = self.functions.get_mut(&hash).expect("exists");
|
let f = self.functions.get_mut(&hash).expect("exists");
|
||||||
f.comments = Some(
|
f.comments = Some(comments.iter().map(|s| s.as_ref().into()).collect());
|
||||||
comments
|
|
||||||
.as_ref()
|
|
||||||
.iter()
|
|
||||||
.map(|s| s.as_ref().into())
|
|
||||||
.collect(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash
|
hash
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![cfg(not(feature = "no_std"))]
|
#![cfg(not(feature = "no_std"))]
|
||||||
#![cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#![cfg(not(target_arch = "wasm32"))]
|
||||||
|
#![cfg(not(target_arch = "wasm64"))]
|
||||||
|
|
||||||
use crate::func::native::shared_write_lock;
|
use crate::func::native::shared_write_lock;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -11,7 +11,8 @@ mod stat;
|
|||||||
pub use collection::ModuleResolversCollection;
|
pub use collection::ModuleResolversCollection;
|
||||||
pub use dummy::DummyModuleResolver;
|
pub use dummy::DummyModuleResolver;
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
pub use file::FileModuleResolver;
|
pub use file::FileModuleResolver;
|
||||||
pub use stat::StaticModuleResolver;
|
pub use stat::StaticModuleResolver;
|
||||||
|
|
||||||
|
@ -193,7 +193,8 @@ def_package! {
|
|||||||
reg_functions!(lib += arith_numbers; i8, u8, i16, u16, i32, u32, u64);
|
reg_functions!(lib += arith_numbers; i8, u8, i16, u16, i32, u32, u64);
|
||||||
reg_functions!(lib += signed_numbers; i8, i16, i32);
|
reg_functions!(lib += signed_numbers; i8, i16, i32);
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
{
|
{
|
||||||
reg_functions!(lib += arith_num_128; i128, u128);
|
reg_functions!(lib += arith_num_128; i128, u128);
|
||||||
reg_functions!(lib += signed_num_128; i128);
|
reg_functions!(lib += signed_num_128; i128);
|
||||||
@ -237,7 +238,8 @@ gen_arithmetic_functions!(arith_numbers => i8, u8, i16, u16, i32, u32, u64);
|
|||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
gen_arithmetic_functions!(arith_num_128 => i128, u128);
|
gen_arithmetic_functions!(arith_num_128 => i128, u128);
|
||||||
|
|
||||||
gen_signed_functions!(signed_basic => INT);
|
gen_signed_functions!(signed_basic => INT);
|
||||||
@ -248,7 +250,8 @@ gen_signed_functions!(signed_numbers => i8, i16, i32);
|
|||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
gen_signed_functions!(signed_num_128 => i128);
|
gen_signed_functions!(signed_num_128 => i128);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
@ -304,6 +304,7 @@ def_package! {
|
|||||||
reg_range!(lib | "range" => i8, u8, i16, u16, i32, u32, i64, u64);
|
reg_range!(lib | "range" => i8, u8, i16, u16, i32, u32, i64, u64);
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
reg_range!(lib | "range" => i128, u128);
|
reg_range!(lib | "range" => i128, u128);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,6 +316,7 @@ def_package! {
|
|||||||
reg_range!(lib | step "range" => i8, u8, i16, u16, i32, u32, i64, u64);
|
reg_range!(lib | step "range" => i8, u8, i16, u16, i32, u32, i64, u64);
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
reg_range!(lib | step "range" => i128, u128);
|
reg_range!(lib | step "range" => i128, u128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,8 @@ def_package! {
|
|||||||
{
|
{
|
||||||
reg_functions!(lib += numbers; i8, u8, i16, u16, i32, u32, u64);
|
reg_functions!(lib += numbers; i8, u8, i16, u16, i32, u32, u64);
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
reg_functions!(lib += num_128; i128, u128);
|
reg_functions!(lib += num_128; i128, u128);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +71,8 @@ gen_cmp_functions!(numbers => i8, u8, i16, u16, i32, u32, u64);
|
|||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
gen_cmp_functions!(num_128 => i128, u128);
|
gen_cmp_functions!(num_128 => i128, u128);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
@ -66,7 +66,8 @@ def_package! {
|
|||||||
{
|
{
|
||||||
reg_functions!(lib += numbers_to_int::to_int(i8, u8, i16, u16, i32, u32, i64, u64));
|
reg_functions!(lib += numbers_to_int::to_int(i8, u8, i16, u16, i32, u32, i64, u64));
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
reg_functions!(lib += num_128_to_int::to_int(i128, u128));
|
reg_functions!(lib += num_128_to_int::to_int(i128, u128));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,8 @@ def_package! {
|
|||||||
{
|
{
|
||||||
reg_functions!(lib += numbers_to_float::to_float(i8, u8, i16, u16, i32, u32, i64, u32));
|
reg_functions!(lib += numbers_to_float::to_float(i8, u8, i16, u16, i32, u32, i64, u32));
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
reg_functions!(lib += num_128_to_float::to_float(i128, u128));
|
reg_functions!(lib += num_128_to_float::to_float(i128, u128));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,7 +522,8 @@ gen_conversion_as_functions!(numbers_to_float => to_float (i8, u8, i16, u16, i32
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
gen_conversion_as_functions!(num_128_to_float => to_float (i128, u128) -> FLOAT);
|
gen_conversion_as_functions!(num_128_to_float => to_float (i128, u128) -> FLOAT);
|
||||||
|
|
||||||
gen_conversion_as_functions!(basic_to_int => to_int (char) -> INT);
|
gen_conversion_as_functions!(basic_to_int => to_int (char) -> INT);
|
||||||
@ -531,7 +534,8 @@ gen_conversion_as_functions!(numbers_to_int => to_int (i8, u8, i16, u16, i32, u3
|
|||||||
|
|
||||||
#[cfg(not(feature = "only_i32"))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
#[cfg(not(feature = "only_i64"))]
|
#[cfg(not(feature = "only_i64"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
gen_conversion_as_functions!(num_128_to_int => to_int (i128, u128) -> INT);
|
gen_conversion_as_functions!(num_128_to_int => to_int (i128, u128) -> INT);
|
||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
|
@ -274,7 +274,8 @@ mod number_formatting {
|
|||||||
to_binary(value)
|
to_binary(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
pub mod num_128 {
|
pub mod num_128 {
|
||||||
#[rhai_fn(name = "to_hex")]
|
#[rhai_fn(name = "to_hex")]
|
||||||
pub fn u128_to_hex(value: u128) -> ImmutableString {
|
pub fn u128_to_hex(value: u128) -> ImmutableString {
|
||||||
|
@ -7,7 +7,8 @@ use crate::{def_package, Dynamic, EvalAltResult, RhaiResult, RhaiResultOf, INT};
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use crate::FLOAT;
|
use crate::FLOAT;
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
|
#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
|
||||||
|
@ -93,7 +93,8 @@ impl Serializer for &mut DynamicSerializer {
|
|||||||
type SerializeSeq = DynamicSerializer;
|
type SerializeSeq = DynamicSerializer;
|
||||||
type SerializeTuple = DynamicSerializer;
|
type SerializeTuple = DynamicSerializer;
|
||||||
type SerializeTupleStruct = DynamicSerializer;
|
type SerializeTupleStruct = DynamicSerializer;
|
||||||
#[cfg(not(any(feature = "no_object", feature = "no_index")))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
type SerializeTupleVariant = TupleVariantSerializer;
|
type SerializeTupleVariant = TupleVariantSerializer;
|
||||||
#[cfg(any(feature = "no_object", feature = "no_index"))]
|
#[cfg(any(feature = "no_object", feature = "no_index"))]
|
||||||
type SerializeTupleVariant = serde::ser::Impossible<Dynamic, RhaiError>;
|
type SerializeTupleVariant = serde::ser::Impossible<Dynamic, RhaiError>;
|
||||||
@ -629,13 +630,15 @@ impl SerializeStruct for DynamicSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "no_object", feature = "no_index")))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
struct TupleVariantSerializer {
|
struct TupleVariantSerializer {
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
array: crate::Array,
|
array: crate::Array,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature = "no_object", feature = "no_index")))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
impl serde::ser::SerializeTupleVariant for TupleVariantSerializer {
|
impl serde::ser::SerializeTupleVariant for TupleVariantSerializer {
|
||||||
type Ok = Dynamic;
|
type Ok = Dynamic;
|
||||||
type Error = RhaiError;
|
type Error = RhaiError;
|
||||||
|
@ -15,7 +15,8 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
@ -524,7 +525,8 @@ impl Hash for Dynamic {
|
|||||||
value_any.downcast_ref::<i64>().expect(CHECKED).hash(state);
|
value_any.downcast_ref::<i64>().expect(CHECKED).hash(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
if type_id == TypeId::of::<u128>() {
|
if type_id == TypeId::of::<u128>() {
|
||||||
TypeId::of::<u128>().hash(state);
|
TypeId::of::<u128>().hash(state);
|
||||||
value_any.downcast_ref::<u128>().expect(CHECKED).hash(state);
|
value_any.downcast_ref::<u128>().expect(CHECKED).hash(state);
|
||||||
@ -636,13 +638,20 @@ impl fmt::Display for Dynamic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[cfg(not(feature = "f32_float"))]
|
||||||
if _type_id == TypeId::of::<f32>() {
|
if _type_id == TypeId::of::<f32>() {
|
||||||
return fmt::Display::fmt(_value_any.downcast_ref::<f32>().expect(CHECKED), f);
|
return fmt::Display::fmt(_value_any.downcast_ref::<f32>().expect(CHECKED), f);
|
||||||
} else if _type_id == TypeId::of::<f64>() {
|
}
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[cfg(feature = "f32_float")]
|
||||||
|
if _type_id == TypeId::of::<f64>() {
|
||||||
return fmt::Display::fmt(_value_any.downcast_ref::<f64>().expect(CHECKED), f);
|
return fmt::Display::fmt(_value_any.downcast_ref::<f64>().expect(CHECKED), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
|
#[cfg(not(feature = "only_i64"))]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
if _type_id == TypeId::of::<u128>() {
|
if _type_id == TypeId::of::<u128>() {
|
||||||
return fmt::Display::fmt(_value_any.downcast_ref::<u128>().expect(CHECKED), f);
|
return fmt::Display::fmt(_value_any.downcast_ref::<u128>().expect(CHECKED), f);
|
||||||
} else if _type_id == TypeId::of::<i128>() {
|
} else if _type_id == TypeId::of::<i128>() {
|
||||||
@ -735,13 +744,20 @@ impl fmt::Debug for Dynamic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[cfg(not(feature = "f32_float"))]
|
||||||
if _type_id == TypeId::of::<f32>() {
|
if _type_id == TypeId::of::<f32>() {
|
||||||
return fmt::Debug::fmt(_value_any.downcast_ref::<f32>().expect(CHECKED), f);
|
return fmt::Debug::fmt(_value_any.downcast_ref::<f32>().expect(CHECKED), f);
|
||||||
} else if _type_id == TypeId::of::<f64>() {
|
}
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
#[cfg(feature = "f32_float")]
|
||||||
|
if _type_id == TypeId::of::<f64>() {
|
||||||
return fmt::Debug::fmt(_value_any.downcast_ref::<f64>().expect(CHECKED), f);
|
return fmt::Debug::fmt(_value_any.downcast_ref::<f64>().expect(CHECKED), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
|
#[cfg(not(feature = "only_i32"))]
|
||||||
|
#[cfg(not(feature = "only_i64"))]
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
#[cfg(not(target_arch = "wasm64"))]
|
||||||
if _type_id == TypeId::of::<u128>() {
|
if _type_id == TypeId::of::<u128>() {
|
||||||
return fmt::Debug::fmt(_value_any.downcast_ref::<u128>().expect(CHECKED), f);
|
return fmt::Debug::fmt(_value_any.downcast_ref::<u128>().expect(CHECKED), f);
|
||||||
} else if _type_id == TypeId::of::<i128>() {
|
} else if _type_id == TypeId::of::<i128>() {
|
||||||
@ -942,7 +958,6 @@ impl Dynamic {
|
|||||||
///
|
///
|
||||||
/// Not available under `no_float`.
|
/// Not available under `no_float`.
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
#[cfg(not(feature = "f32_float"))]
|
|
||||||
pub const FLOAT_PI: Self = Self::from_float(FloatConstants::PI);
|
pub const FLOAT_PI: Self = Self::from_float(FloatConstants::PI);
|
||||||
/// A [`Dynamic`] containing π/2.
|
/// A [`Dynamic`] containing π/2.
|
||||||
///
|
///
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![cfg(not(any(feature = "no_index", feature = "no_module")))]
|
#![cfg(not(feature = "no_index"))]
|
||||||
|
#![cfg(not(feature = "no_module"))]
|
||||||
|
|
||||||
use rhai::plugin::*;
|
use rhai::plugin::*;
|
||||||
use rhai::{Engine, EvalAltResult, INT};
|
use rhai::{Engine, EvalAltResult, INT};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#![cfg(not(any(feature = "no_index", feature = "no_module")))]
|
#![cfg(not(feature = "no_index"))]
|
||||||
|
#![cfg(not(feature = "no_module"))]
|
||||||
|
|
||||||
use rhai::plugin::*;
|
use rhai::plugin::*;
|
||||||
use rhai::{Engine, EvalAltResult, Module, INT};
|
use rhai::{Engine, EvalAltResult, Module, INT};
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#![cfg(not(feature = "no_std"))]
|
#![cfg(not(feature = "no_std"))]
|
||||||
#![cfg(not(target_arch = "wasm32"))]
|
#![cfg(not(target_arch = "wasm32"))]
|
||||||
|
#![cfg(not(target_arch = "wasm64"))]
|
||||||
|
|
||||||
use rhai::{Engine, EvalAltResult};
|
use rhai::{Engine, EvalAltResult};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user