Code cleanup
This commit is contained in:
parent
ca64668e58
commit
4f771d904a
@ -5,7 +5,7 @@ use crate::calc_fn_hash;
|
|||||||
use crate::engine::{
|
use crate::engine::{
|
||||||
search_imports, search_namespace, search_scope_only, Engine, Imports, State, KEYWORD_DEBUG,
|
search_imports, search_namespace, search_scope_only, Engine, Imports, State, KEYWORD_DEBUG,
|
||||||
KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_PRINT,
|
KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY, KEYWORD_PRINT,
|
||||||
KEYWORD_TYPE_OF, KEYWORD_SHARED, KEYWORD_TAKE
|
KEYWORD_TYPE_OF, KEYWORD_SHARED,
|
||||||
};
|
};
|
||||||
use crate::error::ParseErrorType;
|
use crate::error::ParseErrorType;
|
||||||
use crate::fn_native::{FnCallArgs, FnPtr};
|
use crate::fn_native::{FnCallArgs, FnPtr};
|
||||||
@ -31,7 +31,7 @@ use crate::parser::FLOAT;
|
|||||||
use crate::engine::{FN_IDX_GET, FN_IDX_SET};
|
use crate::engine::{FN_IDX_GET, FN_IDX_SET};
|
||||||
|
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
use crate::engine::{Map, Target, FN_GET, FN_SET};
|
use crate::engine::{Map, Target, FN_GET, FN_SET, KEYWORD_TAKE};
|
||||||
|
|
||||||
use crate::stdlib::{
|
use crate::stdlib::{
|
||||||
any::{type_name, TypeId},
|
any::{type_name, TypeId},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Module defining interfaces to native-Rust functions.
|
//! Module defining interfaces to native-Rust functions.
|
||||||
|
|
||||||
use crate::any::{Dynamic, Variant};
|
use crate::any::Dynamic;
|
||||||
use crate::calc_fn_hash;
|
use crate::calc_fn_hash;
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
|
@ -15,7 +15,7 @@ use crate::stdlib::{
|
|||||||
any::TypeId,
|
any::TypeId,
|
||||||
boxed::Box,
|
boxed::Box,
|
||||||
mem,
|
mem,
|
||||||
string::{String, ToString},
|
string::String,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Trait to register custom functions with the `Engine`.
|
/// Trait to register custom functions with the `Engine`.
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
#![cfg(not(feature = "no_function"))]
|
#![cfg(not(feature = "no_function"))]
|
||||||
use rhai::{Dynamic, Engine, EvalAltResult, RegisterFn, FnPtr, Module, INT, Array};
|
use rhai::{Dynamic, Engine, EvalAltResult, FnPtr, Module, INT};
|
||||||
use std::any::{TypeId, Any};
|
use std::any::TypeId;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_shared"))]
|
||||||
|
use rhai::RegisterFn;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
use rhai::Array;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
||||||
@ -35,7 +41,7 @@ fn test_fn_ptr_curry_call() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "no_capture"))]
|
#[cfg(all(not(feature = "no_capture"), not(feature = "no_object")))]
|
||||||
fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
fn test_closures() -> Result<(), Box<EvalAltResult>> {
|
||||||
let engine = Engine::new();
|
let engine = Engine::new();
|
||||||
|
|
||||||
@ -110,6 +116,8 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
'x'
|
'x'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
{
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<String>(
|
engine.eval::<String>(
|
||||||
r#"
|
r#"
|
||||||
@ -124,8 +132,6 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
"teSt"
|
"teSt"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_index"))]
|
|
||||||
{
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<Array>(
|
engine.eval::<Array>(
|
||||||
r#"
|
r#"
|
||||||
@ -137,6 +143,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
5
|
5
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<INT>(
|
engine.eval::<INT>(
|
||||||
r"
|
r"
|
||||||
@ -170,6 +177,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<INT>(
|
engine.eval::<INT>(
|
||||||
r#"
|
r#"
|
||||||
@ -250,6 +258,8 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
42
|
42
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
{
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct TestStruct {
|
struct TestStruct {
|
||||||
x: INT,
|
x: INT,
|
||||||
@ -277,14 +287,13 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.register_type::<TestStruct>();
|
engine
|
||||||
|
.register_type::<TestStruct>()
|
||||||
engine.register_get_set("x", TestStruct::get_x, TestStruct::set_x);
|
.register_get_set("x", TestStruct::get_x, TestStruct::set_x)
|
||||||
engine.register_fn("update", TestStruct::update);
|
.register_fn("update", TestStruct::update)
|
||||||
engine.register_fn("merge", TestStruct::merge);
|
.register_fn("merge", TestStruct::merge)
|
||||||
engine.register_fn("new_ts", TestStruct::new);
|
.register_fn("new_ts", TestStruct::new)
|
||||||
engine.
|
.register_raw_fn(
|
||||||
register_raw_fn(
|
|
||||||
"mutate_with_cb",
|
"mutate_with_cb",
|
||||||
&[
|
&[
|
||||||
TypeId::of::<TestStruct>(),
|
TypeId::of::<TestStruct>(),
|
||||||
@ -339,6 +348,7 @@ fn test_shared() -> Result<(), Box<EvalAltResult>> {
|
|||||||
)?,
|
)?,
|
||||||
2151
|
2151
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user