Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/src/test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ pub fn execute_with_history(source: &str, bars: &[Bar]) -> Result<(), pine::Erro
let historical_data = BenchHistoricalData::new(bars.to_vec());
historical_data.set_current_bar(bars.len() - 1);
script.set_historical_provider(Box::new(historical_data));
script.execute(&bars[bars.len() - 1])?;
let _output = script.execute(&bars[bars.len() - 1])?;
Ok(())
}
51 changes: 50 additions & 1 deletion crates/pine-builtin-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,61 @@ fn generate_value_conversion(
) -> proc_macro2::TokenStream {
let type_str = quote! { #field_type }.to_string();

let conversion = if type_str.contains("f64") {
// Check if this is an Option type
let is_option = type_str.contains("Option");

let conversion = if is_option {
// For Option types, handle Na values
// Check for Color BEFORE other types since Value might also be in the type string
if type_str.contains("Color") && !type_str.contains("Value") {
quote! {
if matches!(arg_value, Value::Na) {
None
} else {
Some(arg_value.as_color()?)
}
}
} else if type_str.contains("f64") {
quote! {
if matches!(arg_value, Value::Na) {
None
} else {
Some(arg_value.as_number()?)
}
}
} else if type_str.contains("String") {
quote! {
if matches!(arg_value, Value::Na) {
None
} else {
Some(arg_value.as_string()?)
}
}
} else if type_str.contains("bool") {
quote! {
if matches!(arg_value, Value::Na) {
None
} else {
Some(arg_value.as_bool()?)
}
}
} else {
quote! {
if matches!(arg_value, Value::Na) {
None
} else {
Some(arg_value)
}
}
}
} else if type_str.contains("f64") {
quote! { arg_value.as_number()? }
} else if type_str.contains("String") {
quote! { arg_value.as_string()? }
} else if type_str.contains("bool") {
quote! { arg_value.as_bool()? }
} else if type_str.contains("Color") {
quote! { arg_value.as_color()? }
} else if type_str.contains("Value") {
quote! { arg_value }
} else {
Expand Down
Loading
Loading