diff --git a/src/main/java/com/hbm/module/ParseMSES1.java b/src/main/java/com/hbm/module/ParseMSES1.java index 1814d3b7c..909dc5dd6 100644 --- a/src/main/java/com/hbm/module/ParseMSES1.java +++ b/src/main/java/com/hbm/module/ParseMSES1.java @@ -111,6 +111,17 @@ public class ParseMSES1 implements IParse { return EnumStatementReturn.OK; } + // runs the calculation from the buffer, allows string substitution, saves result to buffer + if(lower.equals("eval")) { + if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; + String statement = substitute(ctx, ctx.readBuffer(), true); + try { + double result = Calculator.evaluateExpression(statement); + ctx.writeBuffer("" + result); + } catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; } + return EnumStatementReturn.OK; + } + // runs the calculation, allows string substitution, rounds, saves result to buffer, if(lower.startsWith("evalr ")) { if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR; @@ -122,7 +133,7 @@ public class ParseMSES1 implements IParse { return EnumStatementReturn.OK; } - // runs the calculation from the buffer, allows string substitution, saves result to buffer + // runs the calculation from the buffer, allows string substitution, saves rounded result to buffer if(lower.equals("evalr")) { if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR; String statement = substitute(ctx, ctx.readBuffer(), true); diff --git a/src/main/java/com/hbm/module/ParseMSES1Ext1.java b/src/main/java/com/hbm/module/ParseMSES1Ext1.java index d59ce6ee3..db4a3bc48 100644 --- a/src/main/java/com/hbm/module/ParseMSES1Ext1.java +++ b/src/main/java/com/hbm/module/ParseMSES1Ext1.java @@ -3,6 +3,9 @@ package com.hbm.module; import java.util.Locale; import java.util.regex.Pattern; +import com.hbm.tileentity.network.RTTYSystem; +import com.hbm.tileentity.network.RTTYSystem.RTTYChannel; + /** * MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1) * @@ -10,6 +13,7 @@ import java.util.regex.Pattern; * * Support for splitter chars, splitting and split count * * Support for the stack, a secondary buffer that can push, pop and peek * * Support for getting string length and substring using first and last + * * Support for listening only to recent RoR signals using poll * * @author hbm */ @@ -108,6 +112,14 @@ public class ParseMSES1Ext1 extends ParseMSES1 { } catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; } } + // listens to an RoR signal using the supplied channel name and saves it to the buffer + if(lower.startsWith("poll ")) { + if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR; + RTTYChannel chan = RTTYSystem.listen(ctx.world, substitute(ctx, line.substring(5), false)); + if(chan != null && chan.timeStamp >= ctx.world.getTotalWorldTime() - 1) ctx.writeBuffer(chan.signal + ""); + return EnumStatementReturn.OK; + } + return super.eval(ctx, line); } }