Hi, i have one problem i can't solve. I'm making options for user to write script in my app. I would like to implement function cross like the one on https://www.tradingview.com/study-sc...nce/#fun_cross
this is my implementation,
Qt Code:
  1. bool MathScript::cross(int a, int b)
  2. {
  3. bool ret = false;
  4.  
  5. if(a > b && aPrev < bPrev)
  6. ret = true;
  7.  
  8. if(a < b && aPrev > bPrev)
  9. ret = true;
  10.  
  11. return ret;
  12. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. m_Engine = new QScriptEngine(this);
  2.  
  3. MathScript *scriptMath = new MathScript;
  4.  
  5. QScriptValue objectValueMath = m_Engine->newQObject(scriptMath);
  6. m_Engine->globalObject().setProperty("math", objectValueMath);
  7.  
  8. QScriptValue result = m_Engine->evaluate("math.cross(10, 10");
  9. qDebug() << "evaluate " << result.toBool();
To copy to clipboard, switch view to plain text mode 

Now this, is working, but it is wrong. The problem is i need to store previous values, inside cross(), now sure how to do that. The code is evaluated, then new data comes in, so it has to store previous values.
I guess one solution would be to use
Qt Code:
  1. context->callee().setProperty("Aprev", context->argument(0));
To copy to clipboard, switch view to plain text mode 

but this would be working only for one math.cross();
but the user can enter multiple of them, example
var r1 = math.cross(1, 2);
var r2 = math.cross(3, 4);