34 lines
858 B
Plaintext
34 lines
858 B
Plaintext
// calculator.rhai
|
|
// This script demonstrates using the Calculator struct from Rust in Rhai
|
|
|
|
// Create a new calculator
|
|
let calc = new_calculator();
|
|
println("Created a new calculator with value: " + calc.value);
|
|
|
|
// Perform some calculations
|
|
calc.add(5);
|
|
println("After adding 5: " + calc.value);
|
|
|
|
calc.multiply(2);
|
|
println("After multiplying by 2: " + calc.value);
|
|
|
|
calc.subtract(3);
|
|
println("After subtracting 3: " + calc.value);
|
|
|
|
calc.divide(2);
|
|
println("After dividing by 2: " + calc.value);
|
|
|
|
// Set value directly
|
|
calc.value = 100;
|
|
println("After setting value to 100: " + calc.value);
|
|
|
|
// Clear the calculator
|
|
calc.clear();
|
|
println("After clearing: " + calc.value);
|
|
|
|
// Chain operations
|
|
let result = calc.add(10).multiply(2).subtract(5).divide(3);
|
|
println("Result of chained operations: " + result);
|
|
|
|
println("Final calculator value: " + calc.value);
|