dyneveal.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. setup.qsp_dyneval = (code, ...args) => {
  2. const startTime = (new Date()).getTime();
  3. code = code.replaceAll('###NL###','\n').replaceAll("\t","\n")+"\n";
  4. let codeParsed = "";
  5. try{
  6. codeParsed = setup.qsrc2tw(code);
  7. }
  8. catch(e){
  9. console.error("Failed to execute code:",code.replaceAll("\n","*NL*"),e);
  10. }
  11. const old$Result = QSP.$result[0];
  12. const oldResult = QSP.result[0];
  13. QSP.$result[0] = "";
  14. QSP.result[0] = 0;
  15. State.variables.ARGSstack.push(args);
  16. const oldScope = setup.qsp_performAnal_current;
  17. const myScope = {type:'dyneval',code:codeParsed,args:clone(args),entries: []};
  18. oldScope.entries.push(myScope);
  19. setup.qsp_performAnal_current = myScope;
  20. setup.qsp_callStack.push({type:"dyneval",code:codeParsed});
  21. try{
  22. $.wiki(codeParsed);
  23. }
  24. finally{
  25. setup.qsp_performAnal_current = oldScope;
  26. State.variables.ARGSstack.pop();
  27. setup.qsp_callStack.pop();
  28. }
  29. const $result = QSP.$result[0];
  30. const result = QSP.result[0];
  31. QSP.$result[0] = old$Result;
  32. QSP.result[0] = oldResult;
  33. const endTime = (new Date()).getTime();
  34. const executionTime = endTime - startTime;
  35. myScope.executionTime = executionTime;
  36. if(result){
  37. //console.log("DYNEVAL", codeParsed, result);
  38. return result;
  39. }
  40. //console.log("DYNEVAL", codeParsed, $result);
  41. return $result;
  42. };