Add global vars to RPN
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getChatVar } from "../parser";
|
||||
import { getChatVar, getGlobalChatVar } from "../parser";
|
||||
|
||||
function toRPN(expression:string) {
|
||||
let outputQueue = '';
|
||||
@@ -114,6 +114,13 @@ function executeRPNCalculation(text:string) {
|
||||
return "0"
|
||||
}
|
||||
return parsed.toString()
|
||||
}).replace(/\@([a-zA-Z0-9_]+)/g, (_, p1) => {
|
||||
const v = getGlobalChatVar(p1)
|
||||
const parsed = parseFloat(v)
|
||||
if(isNaN(parsed)){
|
||||
return "0"
|
||||
}
|
||||
return parsed.toString()
|
||||
}).replace(/&&/g, '&').replace(/\|\|/g, '|').replace(/<=/g, '≤').replace(/>=/g, '≥').replace(/==/g, '=').replace(/null/gi, '0')
|
||||
const expression = toRPN(text);
|
||||
const evaluated = calculateRPN(expression);
|
||||
|
||||
Reference in New Issue
Block a user