stuff around publishing crate successfuly done
This commit is contained in:
61
steel_decimal/examples/basic_usage.rs
Normal file
61
steel_decimal/examples/basic_usage.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
// examples/basic_usage.rs
|
||||
use steel_decimal::SteelDecimal;
|
||||
use steel::steel_vm::engine::Engine;
|
||||
|
||||
fn main() {
|
||||
// Create a new Steel Decimal engine
|
||||
let steel_decimal = SteelDecimal::new();
|
||||
|
||||
// Transform a simple math expression
|
||||
let script = "(+ 1.5 2.3)";
|
||||
let transformed = steel_decimal.transform(script);
|
||||
println!("Original: {}", script);
|
||||
println!("Transformed: {}", transformed);
|
||||
|
||||
// Create Steel VM and register functions
|
||||
let mut vm = Engine::new();
|
||||
steel_decimal.register_functions(&mut vm);
|
||||
|
||||
// Execute the transformed script
|
||||
match vm.compile_and_run_raw_program(transformed) {
|
||||
Ok(results) => {
|
||||
println!("Results: {:?}", results);
|
||||
if let Some(last_result) = results.last() {
|
||||
println!("Final result: {:?}", last_result);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Try a more complex expression
|
||||
let complex_script = "(+ (* 2.5 3.0) (/ 15.0 3.0))";
|
||||
let complex_transformed = steel_decimal.transform(complex_script);
|
||||
println!("\nComplex original: {}", complex_script);
|
||||
println!("Complex transformed: {}", complex_transformed);
|
||||
|
||||
match vm.compile_and_run_raw_program(complex_transformed) {
|
||||
Ok(results) => {
|
||||
if let Some(last_result) = results.last() {
|
||||
println!("Complex result: {:?}", last_result);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Using the convenience method
|
||||
println!("\nUsing convenience method:");
|
||||
match steel_decimal.parse_and_execute("(+ 10.5 20.3)") {
|
||||
Ok(results) => {
|
||||
if let Some(last_result) = results.last() {
|
||||
println!("Convenience result: {:?}", last_result);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Error: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user