take() keyword; shared test with registered functions with callbacks
This commit is contained in:
@@ -568,7 +568,7 @@ impl Dynamic {
|
||||
///
|
||||
/// ## Safety
|
||||
///
|
||||
/// Both situations normally shouldn't happen since all operations in Rhai
|
||||
/// Both situations normally shouldn't happen since most operations in Rhai
|
||||
/// use pass-by-value data and the script executed in a single thread.
|
||||
///
|
||||
/// # Example
|
||||
@@ -741,7 +741,9 @@ impl Dynamic {
|
||||
}
|
||||
|
||||
/// Get a copy of a specific type to the `Dynamic`.
|
||||
/// Casting to `Dynamic` just returns a reference to it.
|
||||
/// Casting to `Dynamic` returns a clone of the value in case of NON-shared
|
||||
/// Dynamic. In case of Shared Dynamic returns a clone of the inner data of
|
||||
/// Shared Dynamic.
|
||||
/// Returns `None` if the cast fails.
|
||||
#[inline(always)]
|
||||
pub fn read<T: Variant + Clone>(&self) -> Option<T> {
|
||||
|
@@ -93,6 +93,7 @@ pub const KEYWORD_FN_PTR: &str = "Fn";
|
||||
pub const KEYWORD_FN_PTR_CALL: &str = "call";
|
||||
pub const KEYWORD_FN_PTR_CURRY: &str = "curry";
|
||||
pub const KEYWORD_SHARED: &str = "shared";
|
||||
pub const KEYWORD_TAKE: &str = "take";
|
||||
pub const KEYWORD_THIS: &str = "this";
|
||||
pub const FN_TO_STRING: &str = "to_string";
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
|
@@ -5,7 +5,7 @@ use crate::calc_fn_hash;
|
||||
use crate::engine::{
|
||||
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_TYPE_OF, KEYWORD_SHARED
|
||||
KEYWORD_TYPE_OF, KEYWORD_SHARED, KEYWORD_TAKE
|
||||
};
|
||||
use crate::error::ParseErrorType;
|
||||
use crate::fn_native::{FnCallArgs, FnPtr};
|
||||
@@ -593,6 +593,9 @@ impl Engine {
|
||||
.into(),
|
||||
false,
|
||||
))
|
||||
} else if _fn_name == KEYWORD_TAKE {
|
||||
// take call
|
||||
return Ok((obj.read::<Dynamic>().unwrap(), false));
|
||||
} else {
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
let redirected;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::engine::{
|
||||
Engine, KEYWORD_DEBUG, KEYWORD_EVAL, KEYWORD_FN_PTR, KEYWORD_FN_PTR_CALL, KEYWORD_FN_PTR_CURRY,
|
||||
KEYWORD_SHARED, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF,
|
||||
KEYWORD_SHARED, KEYWORD_TAKE, KEYWORD_PRINT, KEYWORD_THIS, KEYWORD_TYPE_OF,
|
||||
};
|
||||
|
||||
use crate::error::LexError;
|
||||
@@ -503,11 +503,12 @@ impl Token {
|
||||
"===" | "!==" | "->" | "<-" | "=>" | ":=" | "::<" | "(*" | "*)" | "#" | "public"
|
||||
| "new" | "use" | "module" | "package" | "var" | "static" | "with" | "do" | "each"
|
||||
| "then" | "goto" | "exit" | "switch" | "match" | "case" | "try" | "catch"
|
||||
| "default" | "void" | "null" | "nil" | "spawn" | "go" | "shared" | "sync"
|
||||
| "default" | "void" | "null" | "nil" | "spawn" | "go" | "sync"
|
||||
| "async" | "await" | "yield" => Reserved(syntax.into()),
|
||||
|
||||
KEYWORD_PRINT | KEYWORD_DEBUG | KEYWORD_TYPE_OF | KEYWORD_EVAL | KEYWORD_FN_PTR
|
||||
| KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY | KEYWORD_SHARED | KEYWORD_THIS => Reserved(syntax.into()),
|
||||
| KEYWORD_FN_PTR_CALL | KEYWORD_FN_PTR_CURRY | KEYWORD_SHARED
|
||||
| KEYWORD_TAKE |KEYWORD_THIS => Reserved(syntax.into()),
|
||||
|
||||
_ => return None,
|
||||
})
|
||||
@@ -1440,7 +1441,7 @@ pub fn is_keyword_function(name: &str) -> bool {
|
||||
|
||||
#[cfg(not(feature = "no-shared"))]
|
||||
{
|
||||
result = result || name == KEYWORD_SHARED;
|
||||
result = result || name == KEYWORD_SHARED || name == KEYWORD_TAKE;
|
||||
}
|
||||
|
||||
result
|
||||
|
Reference in New Issue
Block a user