using uCalcSoftware;

var uc = new uCalc();
// --- Main Application Context ---
// The implicit 'uc' object is the initial default.
uCalc.DefaultInstance.DefineConstant("PI = 3.14159");
Console.WriteLine($"Initial Count: {uCalc.DefaultCount}");

// --- A Plugin needs a temporary, isolated context ---
using (var moduleCalc = new uCalc()) {
   moduleCalc.IsDefault = true; // Push the new instance onto the stack.
   Console.WriteLine($"Count after module pushes new default: {uCalc.DefaultCount}");

   // The module's context is now active.
   // uCalc::DefaultInstance() would now return 'moduleCalc'.
}

// When 'moduleCalc' goes out of scope, it's destroyed and automatically
// removed from the stack, restoring the previous default.

Console.WriteLine($"Count after module instance is disposed: {uCalc.DefaultCount}");

// Verify the original default instance is active again.
var result = uCalc.DefaultInstance.EvalStr("PI");
Console.WriteLine($"Original context restored. PI = {result}");