dyneveal.js 992 B

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