Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
use crate::shared::models::UserSession;
|
|
|
|
|
use crate::shared::state::AppState;
|
|
|
|
|
use log::debug;
|
|
|
|
|
use rhai::Engine;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
pub fn round_keyword(_state: &Arc<AppState>, _user: UserSession, engine: &mut Engine) {
|
|
|
|
|
engine.register_fn("ROUND", |n: f64| -> i64 { n.round() as i64 });
|
|
|
|
|
engine.register_fn("ROUND", |n: f64, decimals: i64| -> f64 {
|
|
|
|
|
let factor = 10_f64.powi(decimals as i32);
|
|
|
|
|
(n * factor).round() / factor
|
|
|
|
|
});
|
|
|
|
|
engine.register_fn("round", |n: f64| -> i64 { n.round() as i64 });
|
|
|
|
|
engine.register_fn("round", |n: f64, decimals: i64| -> f64 {
|
|
|
|
|
let factor = 10_f64.powi(decimals as i32);
|
|
|
|
|
(n * factor).round() / factor
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
debug!("Registered ROUND keyword");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_round_basic() {
|
|
|
|
|
assert_eq!(3.7_f64.round() as i64, 4);
|
|
|
|
|
assert_eq!(3.2_f64.round() as i64, 3);
|
|
|
|
|
assert_eq!((-3.7_f64).round() as i64, -4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_round_decimals() {
|
2025-12-21 23:40:43 -03:00
|
|
|
let n = 2.71828_f64;
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
let decimals = 2;
|
|
|
|
|
let factor = 10_f64.powi(decimals);
|
|
|
|
|
let result = (n * factor).round() / factor;
|
2025-12-21 23:40:43 -03:00
|
|
|
assert!((result - 2.72).abs() < 0.001);
|
Looking at this diff, I can see it's a comprehensive documentation
update and code refactoring focused on:
1. Adding new documentation pages to the table of contents
2. Restructuring the bot templates documentation
3. Changing keyword syntax from underscore format to space format (e.g.,
`SET_BOT_MEMORY` → `SET BOT MEMORY`)
4. Updating compiler and keyword registration to support the new
space-based syntax
5. Adding new keyword modules (social media, lead scoring, templates,
etc.)
Refactor BASIC keywords to use spaces instead of underscores
Change keyword syntax from underscore format (SET_BOT_MEMORY) to more
natural space-separated format (SET BOT MEMORY) throughout the codebase.
Key changes:
- Update Rhai custom syntax registration to use space tokens
- Simplify compiler preprocessing (fewer replacements needed)
- Update all template .bas files to use new syntax
- Expand documentation with consolidated examples and new sections
- Add new keyword modules: social_media, lead_scoring, send_template,
core_functions, qrcode, sms, procedures, import_export, llm_macros,
on_form_submit
2025-11-30 10:53:59 -03:00
|
|
|
}
|
|
|
|
|
}
|