Merge pull request #34 from jhwgh1968/plugins

Improve CI and Fix Warnings and Errors
This commit is contained in:
Stephen Chung 2020-08-15 11:13:09 +08:00 committed by GitHub
commit 6b5741ecaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 20 deletions

View File

@ -4,6 +4,7 @@ on:
push:
branches:
- master
- plugins
pull_request: {}
jobs:

View File

@ -3,6 +3,11 @@
#[cfg(no_std)]
use core::mem;
#[cfg(no_std)]
use alloc::format;
#[cfg(not(no_std))]
use std::format;
use std::collections::HashMap;
use quote::{quote, quote_spanned};

View File

@ -3,7 +3,9 @@
use crate::any::{Dynamic, Variant};
use crate::def_package;
use crate::engine::{make_getter, Array, Engine};
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::engine::{Array, Engine};
use crate::fn_native::FnPtr;
use crate::parser::{ImmutableString, INT};
use crate::plugin::*;

View File

@ -1,4 +1,5 @@
use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::fn_native::FnPtr;
use crate::plugin::*;

View File

@ -1,4 +1,5 @@
use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::parser::INT;
use crate::plugin::*;
@ -211,6 +212,8 @@ mod float_functions {
mod float_funcs {
use crate::parser::FLOAT;
use crate::plugin::*;
#[cfg(feature = "no_std")]
use num_traits::float::Float;
#[export_fn]
pub fn floor(x: FLOAT) -> FLOAT {

View File

@ -2,7 +2,9 @@
use crate::any::Dynamic;
use crate::def_package;
use crate::engine::{make_getter, Engine};
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::engine::Engine;
use crate::fn_native::FnPtr;
use crate::parser::{ImmutableString, INT};
use crate::plugin::*;
@ -11,11 +13,8 @@ use crate::utils::StaticVec;
#[cfg(not(feature = "unchecked"))]
use crate::{result::EvalAltResult, token::Position};
#[cfg(not(feature = "no_index"))]
use crate::engine::Array;
use crate::stdlib::{
any::TypeId, boxed::Box, fmt::Display, format, mem, string::ToString, vec::Vec,
any::TypeId, boxed::Box, fmt::Display, format, mem, string::String, string::ToString, vec::Vec,
};
macro_rules! gen_concat_functions {
@ -47,8 +46,6 @@ macro_rules! reg_functions {
def_package!(crate:MoreStringPackage:"Additional string utilities, including string building.", lib, {
reg_functions!(lib += basic; INT, bool, char, FnPtr);
set_exported_fn!(lib, "+", string_funcs::append_unit);
set_exported_fn!(lib, "+", string_funcs::prepend_unit);
#[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))]
@ -64,8 +61,8 @@ def_package!(crate:MoreStringPackage:"Additional string utilities, including str
#[cfg(not(feature = "no_index"))]
{
set_exported_fn!(lib, "+", string_funcs::append_array);
set_exported_fn!(lib, "+", string_funcs::prepend_array);
set_exported_fn!(lib, "+", string_funcs_array::append_array);
set_exported_fn!(lib, "+", string_funcs_array::prepend_array);
}
lib.combine(exported_module!(string_functions));
@ -192,11 +189,28 @@ mod string_functions {
}
}
mod string_funcs {
#[cfg(not(feature = "no_index"))]
mod string_funcs_array {
use crate::engine::Array;
use crate::plugin::*;
use crate::utils::ImmutableString;
use crate::stdlib::string::String;
#[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
}
mod string_funcs {
use crate::parser::INT;
use crate::plugin::*;
use crate::utils::{ImmutableString, StaticVec};
use crate::stdlib::string::{String, ToString};
#[export_fn]
pub fn append_unit(s: ImmutableString, _x: ()) -> ImmutableString {
@ -207,14 +221,6 @@ mod string_funcs {
s
}
#[export_fn]
pub fn append_array(x: &mut ImmutableString, y: Array) -> String {
format!("{}{:?}", x, y)
}
#[export_fn]
pub fn prepend_array(x: &mut Array, y: ImmutableString) -> String {
format!("{:?}{}", x, y)
}
#[export_fn]
pub fn len(s: &mut ImmutableString) -> INT {
s.chars().count() as INT
}

View File

@ -5,6 +5,7 @@
use super::math_basic::MAX_INT;
use crate::def_package;
#[cfg(not(feature = "no_object"))]
use crate::engine::make_getter;
use crate::plugin::*;
use crate::result::EvalAltResult;
@ -98,7 +99,7 @@ fn time_diff(ts1: Instant, ts2: Instant) -> Result<Dynamic, Box<EvalAltResult>>
.into();
}
Ok(-(seconds as INT).into())
Ok(Dynamic::from(-(seconds as INT)))
} else {
let seconds = (ts1 - ts2).as_secs();

View File

@ -3,6 +3,8 @@
pub use crate::{
stdlib::any::TypeId,
stdlib::boxed::Box,
stdlib::format,
stdlib::string::ToString,
stdlib::vec::Vec,
stdlib::vec as new_vec,
stdlib::mem,