Merge pull request #357 from schungx/master
Reflect plugin module/function visibility to generated code.
This commit is contained in:
commit
780665a12e
@ -111,4 +111,4 @@ instant= { version = "0.1" } # WASM implementation of std::time::Instant
|
|||||||
instant= { version = "0.1" } # WASM implementation of std::time::Instant
|
instant= { version = "0.1" } # WASM implementation of std::time::Instant
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = [ "metadata", "internals" ]
|
features = [ "metadata", "internals", "decimal" ]
|
||||||
|
@ -101,7 +101,7 @@ pub fn parse_punctuated_items(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn outer_item_attributes<T: ExportedParams>(
|
pub fn outer_item_attributes<T: ExportedParams>(
|
||||||
args: proc_macro2::TokenStream,
|
args: proc_macro2::TokenStream,
|
||||||
_attr_name: &str,
|
_attr_name: &str,
|
||||||
) -> syn::Result<T> {
|
) -> syn::Result<T> {
|
||||||
@ -116,7 +116,7 @@ pub(crate) fn outer_item_attributes<T: ExportedParams>(
|
|||||||
T::from_info(export_info)
|
T::from_info(export_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn inner_item_attributes<T: ExportedParams>(
|
pub fn inner_item_attributes<T: ExportedParams>(
|
||||||
attrs: &mut Vec<syn::Attribute>,
|
attrs: &mut Vec<syn::Attribute>,
|
||||||
attr_name: &str,
|
attr_name: &str,
|
||||||
) -> syn::Result<T> {
|
) -> syn::Result<T> {
|
||||||
@ -132,7 +132,7 @@ pub(crate) fn inner_item_attributes<T: ExportedParams>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn deny_cfg_attr(attrs: &Vec<syn::Attribute>) -> syn::Result<()> {
|
pub fn deny_cfg_attr(attrs: &Vec<syn::Attribute>) -> syn::Result<()> {
|
||||||
if let Some(cfg_attr) = attrs
|
if let Some(cfg_attr) = attrs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|a| a.path.get_ident().map(|i| *i == "cfg").unwrap_or(false))
|
.find(|a| a.path.get_ident().map(|i| *i == "cfg").unwrap_or(false))
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
#![allow(unused)]
|
|
||||||
|
|
||||||
#[cfg(no_std)]
|
|
||||||
use core::mem;
|
|
||||||
#[cfg(not(no_std))]
|
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
#[cfg(no_std)]
|
#[cfg(no_std)]
|
||||||
use alloc::format;
|
use alloc::format;
|
||||||
#[cfg(not(no_std))]
|
#[cfg(not(no_std))]
|
||||||
@ -14,7 +7,7 @@ use std::borrow::Cow;
|
|||||||
|
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{quote, quote_spanned, ToTokens};
|
||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseStream, Parser},
|
parse::{Parse, ParseStream},
|
||||||
spanned::Spanned,
|
spanned::Spanned,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,7 +75,7 @@ impl FnSpecialAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn flatten_type_groups(ty: &syn::Type) -> &syn::Type {
|
pub fn flatten_type_groups(ty: &syn::Type) -> &syn::Type {
|
||||||
match ty {
|
match ty {
|
||||||
syn::Type::Group(syn::TypeGroup { ref elem, .. })
|
syn::Type::Group(syn::TypeGroup { ref elem, .. })
|
||||||
| syn::Type::Paren(syn::TypeParen { ref elem, .. }) => flatten_type_groups(elem.as_ref()),
|
| syn::Type::Paren(syn::TypeParen { ref elem, .. }) => flatten_type_groups(elem.as_ref()),
|
||||||
@ -90,7 +83,7 @@ pub(crate) fn flatten_type_groups(ty: &syn::Type) -> &syn::Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn print_type(ty: &syn::Type) -> String {
|
pub fn print_type(ty: &syn::Type) -> String {
|
||||||
ty.to_token_stream()
|
ty.to_token_stream()
|
||||||
.to_string()
|
.to_string()
|
||||||
.replace(" , ", ", ")
|
.replace(" , ", ", ")
|
||||||
@ -103,7 +96,7 @@ pub(crate) fn print_type(ty: &syn::Type) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub(crate) struct ExportedFnParams {
|
pub struct ExportedFnParams {
|
||||||
pub name: Vec<String>,
|
pub name: Vec<String>,
|
||||||
pub return_raw: bool,
|
pub return_raw: bool,
|
||||||
pub pure: bool,
|
pub pure: bool,
|
||||||
@ -190,53 +183,20 @@ impl ExportedParams for ExportedFnParams {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
("name", Some(s)) => name.push(s.value()),
|
("name", Some(s)) => name.push(s.value()),
|
||||||
("set", Some(s)) => {
|
|
||||||
special = match special {
|
("index_get", Some(s))
|
||||||
FnSpecialAccess::None => FnSpecialAccess::Property(Property::Set(
|
| ("index_set", Some(s))
|
||||||
syn::Ident::new(&s.value(), s.span()),
|
| ("return_raw", Some(s))
|
||||||
)),
|
| ("pure", Some(s))
|
||||||
_ => return Err(syn::Error::new(item_span.span(), "conflicting setter")),
|
| ("skip", Some(s))
|
||||||
}
|
| ("global", Some(s))
|
||||||
}
|
| ("internal", Some(s)) => {
|
||||||
("get", Some(s)) => {
|
return Err(syn::Error::new(s.span(), "extraneous value"))
|
||||||
special = match special {
|
|
||||||
FnSpecialAccess::None => FnSpecialAccess::Property(Property::Get(
|
|
||||||
syn::Ident::new(&s.value(), s.span()),
|
|
||||||
)),
|
|
||||||
_ => return Err(syn::Error::new(item_span.span(), "conflicting getter")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
("index_get", None) => {
|
|
||||||
special = match special {
|
|
||||||
FnSpecialAccess::None => FnSpecialAccess::Index(Index::Get),
|
|
||||||
_ => {
|
|
||||||
return Err(syn::Error::new(item_span.span(), "conflicting index_get"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
("index_set", None) => {
|
|
||||||
special = match special {
|
|
||||||
FnSpecialAccess::None => FnSpecialAccess::Index(Index::Set),
|
|
||||||
_ => {
|
|
||||||
return Err(syn::Error::new(item_span.span(), "conflicting index_set"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
("index_get", Some(s)) | ("index_set", Some(s)) | ("return_raw", Some(s)) => {
|
|
||||||
return Err(syn::Error::new(s.span(), "extraneous value"))
|
|
||||||
}
|
|
||||||
("pure", None) => pure = true,
|
("pure", None) => pure = true,
|
||||||
("pure", Some(s)) => return Err(syn::Error::new(s.span(), "extraneous value")),
|
|
||||||
("return_raw", None) => return_raw = true,
|
("return_raw", None) => return_raw = true,
|
||||||
("return_raw", Some(s)) => {
|
|
||||||
return Err(syn::Error::new(s.span(), "extraneous value"))
|
|
||||||
}
|
|
||||||
("skip", None) => skip = true,
|
("skip", None) => skip = true,
|
||||||
("skip", Some(s)) => return Err(syn::Error::new(s.span(), "extraneous value")),
|
|
||||||
("global", Some(s)) | ("internal", Some(s)) => {
|
|
||||||
return Err(syn::Error::new(s.span(), "extraneous value"))
|
|
||||||
}
|
|
||||||
("global", None) => match namespace {
|
("global", None) => match namespace {
|
||||||
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Global,
|
FnNamespaceAccess::Unset => namespace = FnNamespaceAccess::Global,
|
||||||
FnNamespaceAccess::Global => (),
|
FnNamespaceAccess::Global => (),
|
||||||
@ -247,6 +207,40 @@ impl ExportedParams for ExportedFnParams {
|
|||||||
FnNamespaceAccess::Internal => (),
|
FnNamespaceAccess::Internal => (),
|
||||||
_ => return Err(syn::Error::new(key.span(), "conflicting namespace")),
|
_ => return Err(syn::Error::new(key.span(), "conflicting namespace")),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
("get", Some(s)) => {
|
||||||
|
special = match special {
|
||||||
|
FnSpecialAccess::None => FnSpecialAccess::Property(Property::Get(
|
||||||
|
syn::Ident::new(&s.value(), s.span()),
|
||||||
|
)),
|
||||||
|
_ => return Err(syn::Error::new(item_span.span(), "conflicting getter")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
("set", Some(s)) => {
|
||||||
|
special = match special {
|
||||||
|
FnSpecialAccess::None => FnSpecialAccess::Property(Property::Set(
|
||||||
|
syn::Ident::new(&s.value(), s.span()),
|
||||||
|
)),
|
||||||
|
_ => return Err(syn::Error::new(item_span.span(), "conflicting setter")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
("index_get", None) => {
|
||||||
|
special = match special {
|
||||||
|
FnSpecialAccess::None => FnSpecialAccess::Index(Index::Get),
|
||||||
|
_ => {
|
||||||
|
return Err(syn::Error::new(item_span.span(), "conflicting index_get"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
("index_set", None) => {
|
||||||
|
special = match special {
|
||||||
|
FnSpecialAccess::None => FnSpecialAccess::Index(Index::Set),
|
||||||
|
_ => {
|
||||||
|
return Err(syn::Error::new(item_span.span(), "conflicting index_set"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(attr, _) => {
|
(attr, _) => {
|
||||||
return Err(syn::Error::new(
|
return Err(syn::Error::new(
|
||||||
key.span(),
|
key.span(),
|
||||||
@ -270,10 +264,10 @@ impl ExportedParams for ExportedFnParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ExportedFn {
|
pub struct ExportedFn {
|
||||||
entire_span: proc_macro2::Span,
|
entire_span: proc_macro2::Span,
|
||||||
signature: syn::Signature,
|
signature: syn::Signature,
|
||||||
is_public: bool,
|
visibility: syn::Visibility,
|
||||||
pass_context: bool,
|
pass_context: bool,
|
||||||
return_dynamic: bool,
|
return_dynamic: bool,
|
||||||
mut_receiver: bool,
|
mut_receiver: bool,
|
||||||
@ -298,8 +292,7 @@ impl Parse for ExportedFn {
|
|||||||
// #[cfg] attributes are not allowed on functions due to what is generated for them
|
// #[cfg] attributes are not allowed on functions due to what is generated for them
|
||||||
crate::attrs::deny_cfg_attr(&fn_all.attrs)?;
|
crate::attrs::deny_cfg_attr(&fn_all.attrs)?;
|
||||||
|
|
||||||
// Determine if the function is public.
|
let visibility = fn_all.vis;
|
||||||
let is_public = matches!(fn_all.vis, syn::Visibility::Public(_));
|
|
||||||
|
|
||||||
// Determine if the function requires a call context
|
// Determine if the function requires a call context
|
||||||
if let Some(first_arg) = fn_all.sig.inputs.first() {
|
if let Some(first_arg) = fn_all.sig.inputs.first() {
|
||||||
@ -408,7 +401,7 @@ impl Parse for ExportedFn {
|
|||||||
Ok(ExportedFn {
|
Ok(ExportedFn {
|
||||||
entire_span,
|
entire_span,
|
||||||
signature: fn_all.sig,
|
signature: fn_all.sig,
|
||||||
is_public,
|
visibility,
|
||||||
pass_context,
|
pass_context,
|
||||||
return_dynamic,
|
return_dynamic,
|
||||||
mut_receiver,
|
mut_receiver,
|
||||||
@ -418,49 +411,51 @@ impl Parse for ExportedFn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ExportedFn {
|
impl ExportedFn {
|
||||||
pub(crate) fn params(&self) -> &ExportedFnParams {
|
#![allow(unused)]
|
||||||
|
|
||||||
|
pub fn params(&self) -> &ExportedFnParams {
|
||||||
&self.params
|
&self.params
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_scope(&mut self, parent_scope: &ExportScope) {
|
pub fn update_scope(&mut self, parent_scope: &ExportScope) {
|
||||||
let keep = match (self.params.skip, parent_scope) {
|
let keep = match (self.params.skip, parent_scope) {
|
||||||
(true, _) => false,
|
(true, _) => false,
|
||||||
(_, ExportScope::PubOnly) => self.is_public,
|
(_, ExportScope::PubOnly) => self.is_public(),
|
||||||
(_, ExportScope::Prefix(s)) => self.name().to_string().starts_with(s),
|
(_, ExportScope::Prefix(s)) => self.name().to_string().starts_with(s),
|
||||||
(_, ExportScope::All) => true,
|
(_, ExportScope::All) => true,
|
||||||
};
|
};
|
||||||
self.params.skip = !keep;
|
self.params.skip = !keep;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn skipped(&self) -> bool {
|
pub fn skipped(&self) -> bool {
|
||||||
self.params.skip
|
self.params.skip
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn pass_context(&self) -> bool {
|
pub fn pass_context(&self) -> bool {
|
||||||
self.pass_context
|
self.pass_context
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn signature(&self) -> &syn::Signature {
|
pub fn signature(&self) -> &syn::Signature {
|
||||||
&self.signature
|
&self.signature
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn mutable_receiver(&self) -> bool {
|
pub fn mutable_receiver(&self) -> bool {
|
||||||
self.mut_receiver
|
self.mut_receiver
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_public(&self) -> bool {
|
pub fn is_public(&self) -> bool {
|
||||||
self.is_public
|
!matches!(self.visibility, syn::Visibility::Inherited)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn span(&self) -> &proc_macro2::Span {
|
pub fn span(&self) -> &proc_macro2::Span {
|
||||||
&self.entire_span
|
&self.entire_span
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn name(&self) -> &syn::Ident {
|
pub fn name(&self) -> &syn::Ident {
|
||||||
&self.signature.ident
|
&self.signature.ident
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn exported_names(&self) -> Vec<syn::LitStr> {
|
pub fn exported_names(&self) -> Vec<syn::LitStr> {
|
||||||
let mut literals: Vec<_> = self
|
let mut literals: Vec<_> = self
|
||||||
.params
|
.params
|
||||||
.name
|
.name
|
||||||
@ -482,24 +477,24 @@ impl ExportedFn {
|
|||||||
literals
|
literals
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn exported_name<'n>(&'n self) -> Cow<'n, str> {
|
pub fn exported_name<'n>(&'n self) -> Cow<'n, str> {
|
||||||
self.params.name.last().map_or_else(
|
self.params.name.last().map_or_else(
|
||||||
|| self.signature.ident.to_string().into(),
|
|| self.signature.ident.to_string().into(),
|
||||||
|s| s.as_str().into(),
|
|s| s.as_str().into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn arg_list(&self) -> impl Iterator<Item = &syn::FnArg> {
|
pub fn arg_list(&self) -> impl Iterator<Item = &syn::FnArg> {
|
||||||
let skip = if self.pass_context { 1 } else { 0 };
|
let skip = if self.pass_context { 1 } else { 0 };
|
||||||
self.signature.inputs.iter().skip(skip)
|
self.signature.inputs.iter().skip(skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn arg_count(&self) -> usize {
|
pub fn arg_count(&self) -> usize {
|
||||||
let skip = if self.pass_context { 1 } else { 0 };
|
let skip = if self.pass_context { 1 } else { 0 };
|
||||||
self.signature.inputs.len() - skip
|
self.signature.inputs.len() - skip
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn return_type(&self) -> Option<&syn::Type> {
|
pub fn return_type(&self) -> Option<&syn::Type> {
|
||||||
if let syn::ReturnType::Type(_, ref ret_type) = self.signature.output {
|
if let syn::ReturnType::Type(_, ref ret_type) = self.signature.output {
|
||||||
Some(flatten_type_groups(ret_type))
|
Some(flatten_type_groups(ret_type))
|
||||||
} else {
|
} else {
|
||||||
@ -593,9 +588,10 @@ impl ExportedFn {
|
|||||||
let input_types_block = self.generate_input_types("Token");
|
let input_types_block = self.generate_input_types("Token");
|
||||||
let return_type_block = self.generate_return_type("Token");
|
let return_type_block = self.generate_return_type("Token");
|
||||||
let dyn_result_fn_block = self.generate_dynamic_fn();
|
let dyn_result_fn_block = self.generate_dynamic_fn();
|
||||||
|
let vis = self.visibility;
|
||||||
quote! {
|
quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod #name {
|
#vis mod #name {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
#impl_block
|
#impl_block
|
||||||
@ -603,6 +599,7 @@ impl ExportedFn {
|
|||||||
#input_names_block
|
#input_names_block
|
||||||
#input_types_block
|
#input_types_block
|
||||||
#return_type_block
|
#return_type_block
|
||||||
|
#[allow(unused)]
|
||||||
#dyn_result_fn_block
|
#dyn_result_fn_block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -713,13 +710,6 @@ impl ExportedFn {
|
|||||||
|
|
||||||
pub fn generate_impl(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
pub fn generate_impl(&self, on_type_name: &str) -> proc_macro2::TokenStream {
|
||||||
let sig_name = self.name().clone();
|
let sig_name = self.name().clone();
|
||||||
let name = self
|
|
||||||
.params
|
|
||||||
.name
|
|
||||||
.last()
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| self.name().to_string());
|
|
||||||
|
|
||||||
let arg_count = self.arg_count();
|
let arg_count = self.arg_count();
|
||||||
let is_method_call = self.mutable_receiver();
|
let is_method_call = self.mutable_receiver();
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ use crate::attrs::{AttrItem, ExportInfo, ExportScope, ExportedParams};
|
|||||||
use crate::function::ExportedFnParams;
|
use crate::function::ExportedFnParams;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
|
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
|
||||||
pub(crate) struct ExportedModParams {
|
pub struct ExportedModParams {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
skip: bool,
|
skip: bool,
|
||||||
pub scope: ExportScope,
|
pub scope: ExportScope,
|
||||||
@ -97,7 +97,7 @@ impl ExportedParams for ExportedModParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Module {
|
pub struct Module {
|
||||||
mod_all: syn::ItemMod,
|
mod_all: syn::ItemMod,
|
||||||
fns: Vec<ExportedFn>,
|
fns: Vec<ExportedFn>,
|
||||||
consts: Vec<ExportedConst>,
|
consts: Vec<ExportedConst>,
|
||||||
@ -257,6 +257,7 @@ impl Module {
|
|||||||
params,
|
params,
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
let mod_vis = mod_all.vis;
|
||||||
let mod_name = mod_all.ident.clone();
|
let mod_name = mod_all.ident.clone();
|
||||||
let (_, orig_content) = mod_all.content.take().unwrap();
|
let (_, orig_content) = mod_all.content.take().unwrap();
|
||||||
let mod_attrs = mem::take(&mut mod_all.attrs);
|
let mod_attrs = mem::take(&mut mod_all.attrs);
|
||||||
@ -282,7 +283,7 @@ impl Module {
|
|||||||
// Regenerate the module with the new content added.
|
// Regenerate the module with the new content added.
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#(#mod_attrs)*
|
#(#mod_attrs)*
|
||||||
pub mod #mod_name {
|
#mod_vis mod #mod_name {
|
||||||
#(#orig_content)*
|
#(#orig_content)*
|
||||||
#(#inner_modules)*
|
#(#inner_modules)*
|
||||||
#mod_gen
|
#mod_gen
|
||||||
@ -292,7 +293,7 @@ impl Module {
|
|||||||
// Regenerate the original module as-is.
|
// Regenerate the original module as-is.
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
#(#mod_attrs)*
|
#(#mod_attrs)*
|
||||||
pub mod #mod_name {
|
#mod_vis mod #mod_name {
|
||||||
#(#orig_content)*
|
#(#orig_content)*
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use quote::{quote, quote_spanned};
|
use quote::{quote, quote_spanned};
|
||||||
use syn::{parse::Parser, spanned::Spanned};
|
use syn::{parse::Parser, spanned::Spanned};
|
||||||
|
|
||||||
pub(crate) fn generated_module_path(
|
pub fn generated_module_path(
|
||||||
fn_path: &syn::Path,
|
fn_path: &syn::Path,
|
||||||
) -> syn::punctuated::Punctuated<syn::PathSegment, syn::Token![::]> {
|
) -> syn::punctuated::Punctuated<syn::PathSegment, syn::Token![::]> {
|
||||||
let mut g = fn_path.clone().segments;
|
let mut g = fn_path.clone().segments;
|
||||||
|
@ -9,9 +9,9 @@ use crate::function::{
|
|||||||
};
|
};
|
||||||
use crate::module::Module;
|
use crate::module::Module;
|
||||||
|
|
||||||
pub(crate) type ExportedConst = (String, Box<syn::Type>, syn::Expr);
|
pub type ExportedConst = (String, Box<syn::Type>, syn::Expr);
|
||||||
|
|
||||||
pub(crate) fn generate_body(
|
pub fn generate_body(
|
||||||
fns: &mut [ExportedFn],
|
fns: &mut [ExportedFn],
|
||||||
consts: &[ExportedConst],
|
consts: &[ExportedConst],
|
||||||
sub_modules: &mut [Module],
|
sub_modules: &mut [Module],
|
||||||
@ -224,7 +224,7 @@ pub(crate) fn generate_body(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn check_rename_collisions(fns: &Vec<ExportedFn>) -> Result<(), syn::Error> {
|
pub fn check_rename_collisions(fns: &Vec<ExportedFn>) -> Result<(), syn::Error> {
|
||||||
fn make_key(name: impl ToString, item_fn: &ExportedFn) -> String {
|
fn make_key(name: impl ToString, item_fn: &ExportedFn) -> String {
|
||||||
item_fn
|
item_fn
|
||||||
.arg_list()
|
.arg_list()
|
||||||
|
@ -272,7 +272,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_do_nothing {
|
pub mod rhai_fn_do_nothing {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -308,6 +308,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn() -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn() -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(do_nothing()))
|
Ok(Dynamic::from(do_nothing()))
|
||||||
}
|
}
|
||||||
@ -325,7 +326,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_do_something {
|
pub mod rhai_fn_do_something {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -362,6 +363,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn(x: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn(x: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(do_something(x)))
|
Ok(Dynamic::from(do_something(x)))
|
||||||
}
|
}
|
||||||
@ -379,7 +381,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_do_something {
|
pub mod rhai_fn_do_something {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -416,6 +418,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn(context: NativeCallContext, x: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(do_something(context, x)))
|
Ok(Dynamic::from(do_something(context, x)))
|
||||||
}
|
}
|
||||||
@ -436,7 +439,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_return_dynamic {
|
pub mod rhai_fn_return_dynamic {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -472,6 +475,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn() -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn() -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(return_dynamic())
|
Ok(return_dynamic())
|
||||||
}
|
}
|
||||||
@ -523,7 +527,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_add_together {
|
pub mod rhai_fn_add_together {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -562,6 +566,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn(x: usize, y: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn(x: usize, y: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(add_together(x, y)))
|
Ok(Dynamic::from(add_together(x, y)))
|
||||||
}
|
}
|
||||||
@ -579,7 +584,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_increment {
|
pub mod rhai_fn_increment {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -623,6 +628,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn(x: &mut usize, y: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn(x: &mut usize, y: usize) -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(increment(x, y)))
|
Ok(Dynamic::from(increment(x, y)))
|
||||||
}
|
}
|
||||||
@ -641,7 +647,7 @@ mod generate_tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let expected_tokens = quote! {
|
let expected_tokens = quote! {
|
||||||
#[allow(unused)]
|
#[automatically_derived]
|
||||||
pub mod rhai_fn_special_print {
|
pub mod rhai_fn_special_print {
|
||||||
use super::*;
|
use super::*;
|
||||||
struct Token();
|
struct Token();
|
||||||
@ -678,6 +684,7 @@ mod generate_tests {
|
|||||||
pub fn token_return_type() -> &'static str {
|
pub fn token_return_type() -> &'static str {
|
||||||
Token().return_type()
|
Token().return_type()
|
||||||
}
|
}
|
||||||
|
#[allow(unused)]
|
||||||
pub fn dynamic_result_fn(message: &str) -> Result<Dynamic, Box<EvalAltResult> > {
|
pub fn dynamic_result_fn(message: &str) -> Result<Dynamic, Box<EvalAltResult> > {
|
||||||
Ok(Dynamic::from(special_print(message)))
|
Ok(Dynamic::from(special_print(message)))
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ impl TestStruct {
|
|||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
self.x += 1000;
|
self.x += 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { x: 1 }
|
Self { x: 1 }
|
||||||
}
|
}
|
||||||
@ -25,17 +24,30 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.register_fn("new_ts", TestStruct::new)
|
.register_fn("new_ts", TestStruct::new)
|
||||||
.register_fn("update", TestStruct::update);
|
.register_fn("update", TestStruct::update);
|
||||||
|
|
||||||
println!(
|
let result = engine.eval::<TestStruct>(
|
||||||
"{:?}",
|
r"
|
||||||
engine.eval::<TestStruct>("let x = new_ts(); x.update(); x")?
|
let x = new_ts();
|
||||||
);
|
x.update();
|
||||||
println!(
|
x
|
||||||
"{:?}",
|
",
|
||||||
engine.eval::<TestStruct>("let x = [new_ts()]; x[0].update(); x[0]")?
|
)?;
|
||||||
);
|
|
||||||
|
println!("{:?}", result);
|
||||||
|
|
||||||
|
let result = engine.eval::<TestStruct>(
|
||||||
|
r"
|
||||||
|
let x = [ new_ts() ];
|
||||||
|
x[0].update();
|
||||||
|
x[0]
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
println!("{:?}", result);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "no_index", feature = "no_object"))]
|
#[cfg(any(feature = "no_index", feature = "no_object"))]
|
||||||
fn main() {}
|
fn main() {
|
||||||
|
panic!("This example does not run under 'no_index' or 'no_object'.")
|
||||||
|
}
|
||||||
|
@ -24,7 +24,13 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.register_fn("new_ts", TestStruct::new)
|
.register_fn("new_ts", TestStruct::new)
|
||||||
.register_fn("update", TestStruct::update);
|
.register_fn("update", TestStruct::update);
|
||||||
|
|
||||||
let result = engine.eval::<TestStruct>("let x = new_ts(); x.update(); x")?;
|
let result = engine.eval::<TestStruct>(
|
||||||
|
r"
|
||||||
|
let x = new_ts();
|
||||||
|
x.update();
|
||||||
|
x
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
println!("result: {}", result.x); // prints 1001
|
println!("result: {}", result.x); // prints 1001
|
||||||
|
|
||||||
@ -32,4 +38,6 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "no_object")]
|
#[cfg(feature = "no_object")]
|
||||||
fn main() {}
|
fn main() {
|
||||||
|
panic!("This example does not run under 'no_object'.");
|
||||||
|
}
|
||||||
|
@ -3,6 +3,8 @@ use rhai::{Engine, EvalAltResult, INT};
|
|||||||
fn main() -> Result<(), Box<EvalAltResult>> {
|
fn main() -> Result<(), Box<EvalAltResult>> {
|
||||||
let engine = Engine::new();
|
let engine = Engine::new();
|
||||||
|
|
||||||
|
engine.consume(r#"print("hello, world!")"#)?;
|
||||||
|
|
||||||
let result = engine.eval::<INT>("40 + 2")?;
|
let result = engine.eval::<INT>("40 + 2")?;
|
||||||
|
|
||||||
println!("Answer: {}", result); // prints 42
|
println!("Answer: {}", result); // prints 42
|
||||||
|
@ -6,9 +6,15 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
|
|
||||||
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
|
engine.eval_with_scope::<()>(&mut scope, "let x = 4 + 5")?;
|
||||||
|
|
||||||
let result = engine.eval_with_scope::<INT>(&mut scope, "x")?;
|
println!("x = {}", scope.get_value::<INT>("x").unwrap());
|
||||||
|
|
||||||
println!("result: {}", result);
|
for _ in 0..10 {
|
||||||
|
let result = engine.eval_with_scope::<INT>(&mut scope, "x += 1; x")?;
|
||||||
|
|
||||||
|
println!("result: {}", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("x = {}", scope.get_value::<INT>("x").unwrap());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#[cfg(not(feature = "serde"))]
|
#[cfg(not(feature = "serde"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(r#"This example requires the "serde" feature which is not enabled by default."#);
|
println!("This example requires the 'serde' feature to run.");
|
||||||
println!("Try: cargo run --features serde --example serde");
|
println!("Try: cargo run --features serde --example serde");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,12 +33,12 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
|||||||
.register_fn("trim", trim_string)
|
.register_fn("trim", trim_string)
|
||||||
.register_fn("len", count_string_bytes)
|
.register_fn("len", count_string_bytes)
|
||||||
.register_fn("index_of", find_substring)
|
.register_fn("index_of", find_substring)
|
||||||
.register_fn("display", |label: &str, x: INT| {
|
// Register string functions using closures
|
||||||
// Register string functions using closures
|
.register_fn("display", |label: &str, value: INT| {
|
||||||
println!("{}: {}", label, x)
|
println!("{}: {}", label, value)
|
||||||
})
|
})
|
||||||
.register_fn("display", |label: ImmutableString, x: &str| {
|
.register_fn("display", |label: ImmutableString, value: &str| {
|
||||||
println!(r#"{}: "{}""#, label, x) // Quote the input string
|
println!(r#"{}: "{}""#, label, value) // Quote the input string
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
use rhai::{Engine, RegisterFn, INT};
|
use rhai::{Engine, RegisterFn, INT};
|
||||||
|
|
||||||
|
#[cfg(feature = "sync")]
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Channel: Script -> Master
|
// Channel: Script -> Master
|
||||||
let (tx_script, rx_master) = std::sync::mpsc::channel();
|
let (tx_script, rx_master) = std::sync::mpsc::channel();
|
||||||
@ -7,10 +10,7 @@ fn main() {
|
|||||||
let (tx_master, rx_script) = std::sync::mpsc::channel();
|
let (tx_master, rx_script) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
let (tx_script, rx_script) = (
|
let (tx_script, rx_script) = (Mutex::new(tx_script), Mutex::new(rx_script));
|
||||||
std::sync::Mutex::new(tx_script),
|
|
||||||
std::sync::Mutex::new(rx_script),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Spawn thread with Engine
|
// Spawn thread with Engine
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
@ -22,7 +22,7 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(not(feature = "sync"))]
|
#[cfg(not(feature = "sync"))]
|
||||||
engine
|
engine
|
||||||
.register_fn("get", move || rx_script.recv().unwrap())
|
.register_fn("get", move || rx_script.recv().unwrap_or_default())
|
||||||
.register_fn("put", move |v: INT| tx_script.send(v).unwrap());
|
.register_fn("put", move |v: INT| tx_script.send(v).unwrap());
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
|
@ -1357,10 +1357,10 @@ impl Dynamic {
|
|||||||
_ => Err(self.type_name()),
|
_ => Err(self.type_name()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Cast the [`Dynamic`] as a [`Decimal`] and return it.
|
/// _(DECIMAL)_ Cast the [`Dynamic`] as a [`Decimal`] and return it.
|
||||||
/// Returns the name of the actual type if the cast fails.
|
/// Returns the name of the actual type if the cast fails.
|
||||||
///
|
///
|
||||||
/// Available only under `decimal`.
|
/// Exported under the `decimal` feature only.
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn as_decimal(self) -> Result<Decimal, &'static str> {
|
pub fn as_decimal(self) -> Result<Decimal, &'static str> {
|
||||||
|
@ -185,10 +185,10 @@ pub const MAX_FUNCTION_EXPR_DEPTH: usize = 16;
|
|||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
pub const MAX_CALL_STACK_DEPTH: usize = 128;
|
pub const MAX_CALL_STACK_DEPTH: usize = 64;
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
pub const MAX_EXPR_DEPTH: usize = 128;
|
pub const MAX_EXPR_DEPTH: usize = 64;
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
|
@ -364,6 +364,27 @@ impl Engine {
|
|||||||
pos: Position,
|
pos: Position,
|
||||||
level: usize,
|
level: usize,
|
||||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn make_error(
|
||||||
|
name: crate::stdlib::string::String,
|
||||||
|
fn_def: &crate::ast::ScriptFnDef,
|
||||||
|
state: &State,
|
||||||
|
err: Box<EvalAltResult>,
|
||||||
|
pos: Position,
|
||||||
|
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||||
|
Err(Box::new(EvalAltResult::ErrorInFunctionCall(
|
||||||
|
name,
|
||||||
|
fn_def
|
||||||
|
.lib
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|m| m.id())
|
||||||
|
.unwrap_or_else(|| state.source.as_ref().map_or_else(|| "", |s| s.as_str()))
|
||||||
|
.to_string(),
|
||||||
|
err,
|
||||||
|
pos,
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
self.inc_operations(state, pos)?;
|
self.inc_operations(state, pos)?;
|
||||||
|
|
||||||
// Check for stack overflow
|
// Check for stack overflow
|
||||||
@ -421,48 +442,23 @@ impl Engine {
|
|||||||
.or_else(|err| match *err {
|
.or_else(|err| match *err {
|
||||||
// Convert return statement to return value
|
// Convert return statement to return value
|
||||||
EvalAltResult::Return(x, _) => Ok(x),
|
EvalAltResult::Return(x, _) => Ok(x),
|
||||||
|
// Error in sub function call
|
||||||
EvalAltResult::ErrorInFunctionCall(name, src, err, _) => {
|
EvalAltResult::ErrorInFunctionCall(name, src, err, _) => {
|
||||||
EvalAltResult::ErrorInFunctionCall(
|
let fn_name = if src.is_empty() {
|
||||||
format!(
|
format!("{} < {}", name, fn_def.name)
|
||||||
"{}{} < {}",
|
} else {
|
||||||
name,
|
format!("{} @ '{}' < {}", name, src, fn_def.name)
|
||||||
if src.is_empty() {
|
};
|
||||||
"".to_string()
|
|
||||||
} else {
|
make_error(fn_name, fn_def, state, err, pos)
|
||||||
format!(" @ '{}'", src)
|
|
||||||
},
|
|
||||||
fn_def.name
|
|
||||||
),
|
|
||||||
fn_def
|
|
||||||
.lib
|
|
||||||
.as_ref()
|
|
||||||
.map(|m| m.id())
|
|
||||||
.flatten()
|
|
||||||
.or_else(|| state.source.as_ref().map(|s| s.as_str()))
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string(),
|
|
||||||
err,
|
|
||||||
pos,
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
// System errors are passed straight-through
|
// System errors are passed straight-through
|
||||||
err if err.is_system_exception() => Err(Box::new(err)),
|
mut err if err.is_system_exception() => Err(Box::new({
|
||||||
|
err.set_position(pos);
|
||||||
|
err
|
||||||
|
})),
|
||||||
// Other errors are wrapped in `ErrorInFunctionCall`
|
// Other errors are wrapped in `ErrorInFunctionCall`
|
||||||
_ => EvalAltResult::ErrorInFunctionCall(
|
_ => make_error(fn_def.name.to_string(), fn_def, state, err, pos),
|
||||||
fn_def.name.to_string(),
|
|
||||||
fn_def
|
|
||||||
.lib
|
|
||||||
.as_ref()
|
|
||||||
.map(|m| m.id())
|
|
||||||
.flatten()
|
|
||||||
.or_else(|| state.source.as_ref().map(|s| s.as_str()))
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string(),
|
|
||||||
err,
|
|
||||||
pos,
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove all local variables
|
// Remove all local variables
|
||||||
|
@ -1738,7 +1738,8 @@ impl Module {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterator over all script-defined functions in the [`Module`].
|
/// _(INTERNALS)_ Get an iterator over all script-defined functions in the [`Module`].
|
||||||
|
/// Exported under the `internals` feature only.
|
||||||
///
|
///
|
||||||
/// Function metadata includes:
|
/// Function metadata includes:
|
||||||
/// 1) Namespace ([`FnNamespace::Global`] or [`FnNamespace::Internal`]).
|
/// 1) Namespace ([`FnNamespace::Global`] or [`FnNamespace::Internal`]).
|
||||||
@ -1746,7 +1747,6 @@ impl Module {
|
|||||||
/// 3) Function name (as string slice).
|
/// 3) Function name (as string slice).
|
||||||
/// 4) Number of parameters.
|
/// 4) Number of parameters.
|
||||||
/// 5) _(INTERNALS)_ Shared reference to function definition [`ScriptFnDef`][crate::ast::ScriptFnDef].
|
/// 5) _(INTERNALS)_ Shared reference to function definition [`ScriptFnDef`][crate::ast::ScriptFnDef].
|
||||||
/// Exported under the `internals` feature only.
|
|
||||||
#[cfg(not(feature = "no_function"))]
|
#[cfg(not(feature = "no_function"))]
|
||||||
#[cfg(feature = "internals")]
|
#[cfg(feature = "internals")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -437,7 +437,7 @@ mod f64_functions {
|
|||||||
|
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
#[export_module]
|
#[export_module]
|
||||||
mod decimal_functions {
|
pub mod decimal_functions {
|
||||||
use rust_decimal::{prelude::Zero, Decimal};
|
use rust_decimal::{prelude::Zero, Decimal};
|
||||||
|
|
||||||
#[rhai_fn(skip, return_raw)]
|
#[rhai_fn(skip, return_raw)]
|
||||||
|
Loading…
Reference in New Issue
Block a user